/// <summary> /// Constructor for the Hotplugger class. Requires an initial method to which send messages when a device is /// connected or disconencted. /// </summary> /// <param name="methodDelegate">The method to be executed when a new controller is connected or disconnected.</param> public Hotplugger(Delegate methodDelegate) { // Create a new CreateParameters object. CreateParams cp = new CreateParams { // Specify HWND_MESSAGE in the hwndParent parameter such that the window only receives messages, no rendering, etc. Parent = (IntPtr)HWND_MESSAGE }; // Create the handle for the message only window. CreateHandle(cp); // Adds the specific delegate such that it is ran upon connecting a controller. _controllerConnectDelegate += (GetConnectedControllersDelegate)methodDelegate; // Register this window to receive controller connect and disconnect notifications. _deviceNotificationDispatcher = new DeviceNotification(Handle, false); }
/// <summary> /// Removes a specific passed in delegate instance if it exists/is currently assigned. /// </summary> public void RemoveDelegate(Delegate methodDelegate) { // Get pointer to function _controllerConnectDelegate -= (GetConnectedControllersDelegate)methodDelegate; }