public CcmErrorCode EnumerateSessions(out CcmIcaSession[] sessions) { var ptrSize = Marshal.SizeOf(typeof(CcmIcaSession)); var ptr = IntPtr.Zero; var result = Environment.Is64BitProcess ? CcmSdk64.CCMEnumerateSessions(out var count, ref ptr) : CcmSdk32.CCMEnumerateSessions(out count, ref ptr); sessions = new CcmIcaSession[count]; for (int i = 0; i < count; i++) { var nPtr = IntPtr.Add(ptr, i * ptrSize); sessions[i] = Marshal.PtrToStructure <CcmIcaSession>(nPtr); } _ = Environment.Is64BitProcess ? CcmSdk64.CCMFreeICASession(count, ptr) : CcmSdk32.CCMFreeICASession(count, ptr); return((CcmErrorCode)result); }