protected void SetupInput() { if (IsOpen) { byte[] buffer = CreateInputBuffer(); __InputBufferPtr = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, __InputBufferPtr, buffer.Length); if (!DeviceGCHandle.IsAllocated) { DeviceGCHandle = GCHandle.Alloc(this); // Schedule the device on the current run loop in case it isn't already scheduled Native.IOHIDDeviceScheduleWithRunLoop(__deviceHandle, RunLoop, Native.RunLoopModeDefault); // _scheduleWithRunLoop=true; // Register a callback Native.IOHIDDeviceRegisterInputReportCallback(__deviceHandle, __InputBufferPtr, buffer.Length, InputReportCallback, GCHandle.ToIntPtr(DeviceGCHandle)); // _registeredToInputReport=true; } } }