Пример #1
0
        public RAWINPUTDEVICELIST[] GetAllHIDDevices()
        {
            IntPtr pnumdevices = Marshal.AllocHGlobal(Marshal.SizeOf <uint>());

            try
            {
                uint retval = Win32Interop.GetRawInputDeviceList(IntPtr.Zero, pnumdevices,
                                                                 (uint)Marshal.SizeOf <RAWINPUTDEVICELIST>());

                if (retval == (uint)0xFFFFFFFF)
                {
                    Win32Interop.GetLastErrorAndThrow();
                }

                var devicesNum = Marshal.PtrToStructure <uint>(pnumdevices);

                var devices = new RAWINPUTDEVICELIST[devicesNum];

                retval = Win32Interop.GetRawInputDeviceList(
                    Marshal.UnsafeAddrOfPinnedArrayElement(devices, 0),
                    pnumdevices,
                    (uint)Marshal.SizeOf <RAWINPUTDEVICELIST>());

                if (retval == (uint)0xFFFFFFFF)
                {
                    Win32Interop.GetLastErrorAndThrow();
                }

                return(devices);
            }
            finally
            {
                Marshal.FreeHGlobal(pnumdevices);
            }
        }
Пример #2
0
        public SL600SDK CreateInstance()
        {
            lock (_syncObj)
            {
                if (_hModule == IntPtr.Zero)
                {
                    _hModule = Win32Interop.LoadLibraryExW(_pathToDll, IntPtr.Zero, 0x00001000);
                    if (_hModule == IntPtr.Zero)
                    {
                        Win32Interop.GetLastErrorAndThrow();
                    }
                }

                if (_thread == null)
                {
                    _thread = new DispathcedThread();
                }

                if (_functions == null)
                {
                    _functions = new FunctionPointersContainer(_hModule);
                }

                var inst = new SL600SDK(_thread, _functions);
                inst.Disposed += Inst_Disposed;
                Interlocked.Increment(ref _refCounter);
                return(inst);
            }
        }
Пример #3
0
 private void Release()
 {
     lock (_syncObj)
     {
         _thread.Dispose();
         _thread    = null;
         _functions = null;
         Win32Interop.FreeLibrary(_hModule);
         _hModule = IntPtr.Zero;
     }
 }
Пример #4
0
        public string GetHIDDeviceName(RAWINPUTDEVICELIST device)
        {
            var strptr = Marshal.AllocHGlobal(255);
            var pSize  = Marshal.AllocHGlobal(Marshal.SizeOf <uint>());

            Marshal.StructureToPtr((uint)255, pSize, false);

            try
            {
                var retval = Win32Interop.GetRawInputDeviceInfoW(device.hDevice, 0x20000007, strptr, pSize);
                if (retval == 0xFFFFFFFF)
                {
                    Win32Interop.GetLastErrorAndThrow();
                }

                return(Marshal.PtrToStringUni(strptr));
            }
            finally
            {
                Marshal.FreeHGlobal(pSize);
                Marshal.FreeHGlobal(strptr);
            }
        }
Пример #5
0
        public RID_DEVICE_INFO GetHIDDeviceInfo(RAWINPUTDEVICELIST device)
        {
            var size          = Marshal.SizeOf <RID_DEVICE_INFO>();
            var infoStructPtr = Marshal.AllocHGlobal(size);
            var pSize         = Marshal.AllocHGlobal(Marshal.SizeOf <uint>());

            Marshal.StructureToPtr(size, pSize, false);

            try
            {
                var retval = Win32Interop.GetRawInputDeviceInfoW(device.hDevice, 0x2000000b, infoStructPtr, pSize);
                if (retval == 0xFFFFFFFF)
                {
                    Win32Interop.GetLastErrorAndThrow();
                }

                return(Marshal.PtrToStructure <RID_DEVICE_INFO>(infoStructPtr));
            }
            finally
            {
                Marshal.FreeHGlobal(pSize);
                Marshal.FreeHGlobal(infoStructPtr);
            }
        }
        public UnmanagedFunctionInfo GetFunctionAddress <T>(string name) where T : Delegate
        {
            if (FunctionPointers.ContainsKey(name))
            {
                return((UnmanagedFunctionInfo)FunctionPointers[name]);
            }

            var res = Win32Interop.GetProcAddress(ModulePtr, name);

            if (res == IntPtr.Zero)
            {
                Win32Interop.GetLastErrorAndThrow();
            }

            var info = new UnmanagedFunctionInfo
            {
                FunctionDelegate = Marshal.GetDelegateForFunctionPointer <T>(res),
                Pointer          = res
            };

            FunctionPointers.Add(name, info);

            return(info);
        }