GetRawInputDeviceInfo returns incorrect syntax for USB HID device name in Windows XP

I am using GetRawInputDeviceInfo to get the device name of the USB device HID name.

For some reason, when I run my code under Windows XP, I get a device name that starts with \??\ rather than \\?\ .

This, of course, means that when I try to use this device name (for example, in CreateFile ), it will not work. If I edit the device name and manually fix it as \\?\ , Everything will be fine.

This does not happen on Windows 7. On Win7, everything works fine.

I also test GetLastError after every API call and errors.

My whole OS is 32 bit and my project is compiled using unicode.

Any suggestions what am I doing wrong? Here are snippets of code from my console application that gets the device name.

 nResult = GetRawInputDeviceInfo( pDeviceList[i].hDevice, RIDI_DEVICENAME, NULL, &nBufferSize ); if( nResult < 0 ) { cout << "ERR: Unable to get Device Name character count.." << endl; return false; } WCHAR* wcDeviceName = new WCHAR[ nBufferSize + 1 ]; if( wcDeviceName == NULL ) { cout << "ERR: Unable to allocate memory for Device Name.." << endl; return false; } nResult = GetRawInputDeviceInfo( pDeviceList[i].hDevice, RIDI_DEVICENAME, wcDeviceName, &nBufferSize ); if( nResult < 0 ) { cout << "ERR: Unable to get Device Name.." << endl; delete [] wcDeviceName; return false; } wcDeviceName[1]='\\'; //This is the manual fix for the device name in WinXP. How do I get rid of it???? pDesc->hHandle = CreateFile(wcDeviceName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL); ... ... 
+4
source share
1 answer

You are not doing anything wrong.

Just change the second character to \ and you will set. What you see is the path of the raw device in its native form ( \??\... ). When you have the form \\?\ , That is, the MS bridge, invented to create long path names on Win32, when NT arrived, despite the limitation of the Win32 subsystem to the object directory \?? .

Read a few sections of Rusinovich's Windows Internals (any old edition will do) and use Sysinternals winobj.exe to explore the Windows object namespace to see what I'm talking about.

Side note: when you call CreateFile , the code in kernel32.dll will literally undo the proposed change and convert it back to its native form before native functions can see the path. So, all you do is make the Win32 layer understandable for the path.

+6
source

Source: https://habr.com/ru/post/1414874/


All Articles