/// <summary> /// Create a new NetLayerWindow object. /// </summary> public NetLayerWindow() { GCHandle Handle = GCHandle.Alloc(this); bool KeepHandle = false; try { CONNECTION_CALLBACKS Callbacks = new CONNECTION_CALLBACKS() { Context = (IntPtr)Handle, OnReceive = Marshal.GetFunctionPointerForDelegate(OnReceiveDelegate), OnSend = Marshal.GetFunctionPointerForDelegate(OnSendDelegate), OnStreamError = Marshal.GetFunctionPointerForDelegate(OnStreamErrorDelegate) }; Connection = AuroraServerNetLayerCreate(IntPtr.Zero, Callbacks); if (Connection == IntPtr.Zero) { throw new OutOfMemoryException("Couldn't create NetLayerWindow object."); } WindowTimer.Tick += WindowTimer_Tick; KeepHandle = true; } finally { if (!KeepHandle) { if (Connection != IntPtr.Zero) { AuroraServerNetLayerDestroy(Connection); Connection = IntPtr.Zero; } Handle.Free(); } } }
/// <summary> /// Create a new NetLayerWindow object. /// </summary> public NetLayerWindow() { GCHandle Handle = GCHandle.Alloc(this); bool KeepHandle = false; try { CONNECTION_CALLBACKS Callbacks = new CONNECTION_CALLBACKS() { Context = (IntPtr)Handle, OnReceive = Marshal.GetFunctionPointerForDelegate(OnReceiveDelegate), OnSend = Marshal.GetFunctionPointerForDelegate(OnSendDelegate), OnStreamError = Marshal.GetFunctionPointerForDelegate(OnStreamErrorDelegate) }; Connection = AuroraServerNetLayerCreate(IntPtr.Zero, Callbacks); if (Connection == IntPtr.Zero) throw new OutOfMemoryException("Couldn't create NetLayerWindow object."); WindowTimer.Tick += WindowTimer_Tick; KeepHandle = true; } finally { if (!KeepHandle) { if (Connection != IntPtr.Zero) { AuroraServerNetLayerDestroy(Connection); Connection = IntPtr.Zero; } Handle.Free(); } } }
private static extern IntPtr AuroraServerNetLayerCreate(IntPtr ExistingInstance, CONNECTION_CALLBACKS Callbacks);