Click here to Skip to main content
12,634,107 members (23,770 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Unmanaged
hi

i want to get device name of HID device using GetRawInputDeviceInfo method of User32.dll. And i am getting window handle from lparam of WndProc Message as mentioned in GetRawInputDeviceInfo function (Windows)[^] but it give pcbSize=0 always.

protected override void WndProc(ref Message m)
        {

            if (m.Msg == 0xFF)
            {
                string deviceName = GetDeviceName(m.LParam);
            }
         }

public string GetDeviceName(IntPtr DeviceHandle)
{
   uint pcbSize = 0;
   string deviceName="";
   GetRawInputDeviceInfo(DeviceHandle, RIDI_DEVICENAME, IntPtr.Zero, ref pcbSize);
   if (pcbSize > 0)
      {
        IntPtr pData = Marshal.AllocHGlobal((int)pcbSize);
        GetRawInputDeviceInfo(DeviceHandle, RIDI_DEVICENAME, pData, ref pcbSize);
        deviceName = Marshal.PtrToStringAnsi(pData);
        Marshal.FreeHGlobal(pData);
        }
   return deviceName;
}


What i am doing wrong here ?
I want to get device name from WndProc message simply.
Posted 30-Nov-12 21:34pm
Updated 30-Nov-12 21:41pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100