Hi,
We are developing a Windows application to be used through Remote Desktop. Within this application we enumerate the HID devices connected to the client using GetRawInputDeviceInfo using the following code (simplified snippets):
private const int RidiDeviceName = 0x20000007;
[DllImport("User32.dll", SetLastError = true)]
private static extern uint GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
[...]
for (int i = 0; i < numDevices; ++i)
{
uint pcbSize = 0;
RawInputDeviceList inputDeviceList =
(RawInputDeviceList)
Marshal.PtrToStructure(new IntPtr((rawInputDeviceList.ToInt64() + (size * i))),
typeof(RawInputDeviceList));
var return_first = GetRawInputDeviceInfo(inputDeviceList.hDevice, RidiDeviceName, IntPtr.Zero, ref pcbSize);
if (pcbSize > 0)
{
var data = Marshal.AllocHGlobal(((int)pcbSize+1)*2);
var return_second = GetRawInputDeviceInfo(inputDeviceList.hDevice, RidiDeviceName, data, ref pcbSize);
string deviceName = Marshal.PtrToStringAnsi(data);
if (!String.IsNullOrEmpty(deviceName) && errorCode == 0)
{
[...]
When running the application on a client pc, the above code works fine and correct device names are found for each device. However when executing the application on a server through Remote Desktop or as RemoteApp, the first call to GetRawInputDeviceInfo only returns pcbSize = 2 and subsequently the second call returns garbled values in the data variable.
When run through Remote Desktop / Remote App, neither of the two calls returns any (windows) error codes (error code is 0) and the first return value (return_first) is 0. The second return value (return_second) is however 4294967295.
Are there any reason as to why the calls to GetRawInputDeviceInfo does not work through Remote Desktop? Are we missing any special permissions/grants which needs to be set or are there some other details we have missed? The user running the code is administrator on the server and should have all permissions.
Best Regards
Morten Klitgaard,
Software Developer & Project Manager
Logimatic, Denmark.