コード例 #1
0
        // Gets the hardware ID.
        private static unsafe string GetDeviceName(IntPtr hDevice)
        {
            uint charCount = 0;


            RID_DEVICE_INFO info = new RID_DEVICE_INFO();

            info.cbSize = (uint)Marshal.SizeOf(typeof(RID_DEVICE_INFO));
            charCount   = info.cbSize;
            uint res = Win32.GetRawInputDeviceInfo(hDevice, Win32.RIDI_DEVICENAME, ref info, ref charCount);

#if DEBUG
            if (res < 1)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
#endif // DEBUG

            string deviceName = String.Empty;

            if (charCount > 0)
            {
                char *pName = stackalloc char[(int)charCount + 1];
                pName[0] = '\0';

                res = Win32.GetRawInputDeviceInfo(hDevice, Win32.RIDI_DEVICENAME, (IntPtr)pName, ref charCount);

#if DEBUG
                if (res != charCount)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
#endif // DEBUG

                deviceName = new string(pName);
            }

            return(deviceName);            // Will never return a null reference.
        }
コード例 #2
0
ファイル: RawInput.cs プロジェクト: zhuangfangwang/ise
		// Gets the hardware ID.
		private static unsafe string GetDeviceName(IntPtr hDevice)
		{
			uint charCount = 0;


			RID_DEVICE_INFO info = new RID_DEVICE_INFO();
			info.cbSize = (uint) Marshal.SizeOf(typeof (RID_DEVICE_INFO));
			charCount = info.cbSize;
			uint res = Win32.GetRawInputDeviceInfo(hDevice, Win32.RIDI_DEVICENAME, ref info, ref charCount);

#if DEBUG
			if (res < 1)
				throw new Win32Exception(Marshal.GetLastWin32Error());
#endif // DEBUG

			string deviceName = String.Empty;

			if (charCount > 0)
			{
				char* pName = stackalloc char[(int)charCount + 1];
				pName[0] = '\0';

				res = Win32.GetRawInputDeviceInfo(hDevice, Win32.RIDI_DEVICENAME, (IntPtr)pName, ref charCount);

#if DEBUG
				if (res != charCount)
					throw new Win32Exception(Marshal.GetLastWin32Error());
#endif // DEBUG

				deviceName = new string(pName);
			}

			return deviceName; // Will never return a null reference.
		}
コード例 #3
0
 public static extern uint GetRawInputDeviceInfo(IntPtr hDevice, uint command, [In] ref RID_DEVICE_INFO ridInfo, ref uint sizeInBytes);