Marshalling Data Question

G

Guest

I am trying to obtain a list of HID devices and am trying to use UINT
GetRawInputDeviceList( PRAWINPUTDEVICELIST pRawInputDeviceList,
PUINT puiNumDevices, UINT cbSize);
a USER32.dll. but the function fails. Here is the code. I am new to
Marshalling. Can anyone suggest my error and why? I am using C# with Visual
Studio 2003 with 1.1 .NET
Code:
/*typedef struct tagRAWINPUTDEVICELIST {
HANDLE hDevice;
DWORD dwType;
} RAWINPUTDEVICELIST, *PRAWINPUTDEVICELIST;
*/
converts to :
[ StructLayout( LayoutKind.Sequential )]
public class RAWINPUTDEVICELIST
{
public IntPtr Device;
public int Type;
}
and
RAWINPUTDEVICELIST pRawInputDeviceList;

/*UINT GetRawInputDeviceList( PRAWINPUTDEVICELIST
pRawInputDeviceList,
PUINT puiNumDevices, UINT cbSize);*/
converts to:
[ DllImport( "C:Windows\\System32\\USER32.DLL" )]
public static extern uint GetRawInputDeviceList( [In, Out]
RAWINPUTDEVICELIST pRawInputDeviceList,[In, Out] uint NumDevices,uint size );

and the call:
uint bb = GetRawInputDeviceList( pRawInputDeviceList, NumDevices, size );
fails and I get the following error:
Unable to load DLL (C:Windows\System32\USER32.DLL).
any suggestions??
 
M

Mattias Sjögren

[ DllImport( "C:Windows\\System32\\USER32.DLL" )]
^^^^

That's not a valid path, you would need a backslash after the colon.
But it's better to remove the path and just specify the file name,
User32.dll.

public static extern uint GetRawInputDeviceList( [In, Out]
RAWINPUTDEVICELIST pRawInputDeviceList,[In, Out] uint NumDevices,uint size );
^^^^^^^^^^^^^^^^^^^^^^^^^

NumDevices should be a ref parameter.


Mattias
 
G

Guest

Thanks, but I am still having difficulty. Here are the changes made:


[ DllImport( "user32.DLL",EntryPoint="GetRawInputDeviceList" )]
public static extern uint GetRawInputDeviceList([In, Out]
RAWINPUTDEVICELIST pRawInputDeviceList, ref uint NumDevices,uint size );

RAWINPUTDEVICELIST pRawInputDeviceList = new RAWINPUTDEVICELIST();
size =
(uint)System.Runtime.InteropServices.Marshal.SizeOf(pRawInputDeviceList);
uint bb = GetRawInputDeviceList( pRawInputDeviceList,ref
NumDevices,size);

This builds ok but I get the following error:
Additional information: Unable to find an entry point named
GetRawInputDeviceList in DLL USER32.DLL. Any thoughts??
--
BP


Mattias Sjögren said:
[ DllImport( "C:Windows\\System32\\USER32.DLL" )]
^^^^

That's not a valid path, you would need a backslash after the colon.
But it's better to remove the path and just specify the file name,
User32.dll.

public static extern uint GetRawInputDeviceList( [In, Out]
RAWINPUTDEVICELIST pRawInputDeviceList,[In, Out] uint NumDevices,uint size );
^^^^^^^^^^^^^^^^^^^^^^^^^

NumDevices should be a ref parameter.


Mattias
 
M

Mattias Sjögren

This builds ok but I get the following error:
Additional information: Unable to find an entry point named
GetRawInputDeviceList in DLL USER32.DLL. Any thoughts??

Wrong operating system perhaps? GetRawInputDeviceList is implemented
on Windows XP and later.


Mattias
 
G

Guest

Gee, your sharp! I did not catch that fact. (Windows 2000). Thanks for your
help!
 
G

Guest

I have a question about how to marshal the PRAWINPUTDEVICELIST
pRawInputDeviceList which is --- >[out] Pointer to buffer that holds an array
of RAWINPUTDEVICELIST structures for the devices attached to the system.
The steps I have followed is to call GetRawInputDeviceList() with
pRawInputDeviceList = null to get the NumDevices. Then create the array
myArray = new RAWINPUTDEVICELIST[NumDevices];

At this point I am unsure as to how to marshal the pRawInputDeviceList above
which is a pointer to the buffer for the method -> GetRawInputDeviceList(
pRawInputDeviceList, NumDevices, size ) . Can you help?

BP


PickwickBob3 said:
Gee, your sharp! I did not catch that fact. (Windows 2000). Thanks for your
help!
--
BP


PickwickBob3 said:
I am trying to obtain a list of HID devices and am trying to use UINT
GetRawInputDeviceList( PRAWINPUTDEVICELIST pRawInputDeviceList,
PUINT puiNumDevices, UINT cbSize);
a USER32.dll. but the function fails. Here is the code. I am new to
Marshalling. Can anyone suggest my error and why? I am using C# with Visual
Studio 2003 with 1.1 .NET
Code:
/*typedef struct tagRAWINPUTDEVICELIST {
HANDLE hDevice;
DWORD dwType;
} RAWINPUTDEVICELIST, *PRAWINPUTDEVICELIST;
*/
converts to :
[ StructLayout( LayoutKind.Sequential )]
public class RAWINPUTDEVICELIST
{
public IntPtr Device;
public int Type;
}
and
RAWINPUTDEVICELIST pRawInputDeviceList;

/*UINT GetRawInputDeviceList( PRAWINPUTDEVICELIST
pRawInputDeviceList,
PUINT puiNumDevices, UINT cbSize);*/
converts to:
[ DllImport( "C:Windows\\System32\\USER32.DLL" )]
public static extern uint GetRawInputDeviceList( [In, Out]
RAWINPUTDEVICELIST pRawInputDeviceList,[In, Out] uint NumDevices,uint size );

and the call:
uint bb = GetRawInputDeviceList( pRawInputDeviceList, NumDevices, size );
fails and I get the following error:
Unable to load DLL (C:Windows\System32\USER32.DLL).
any suggestions??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top