I am relatively new to .net / C # (although very experienced in Win32 / MFC and other platforms), and you need to write a utility to talk to a custom USB HID device. The protocol is quite simple, and I already have a utility utility written in MFC, but I would prefer to write this utility in .Net / C #, as I try to move over time and leave MFC behind.
I did some research and came across this article, which seemed to help me understand how to access HID devices from .Net / C #, especially since it just calls the Win32 API calls that I'm already familiar with:
http://www.developerfusion.com/article/84338/making-usb-c-friendly/
The above code example gave me a great idea on how to access Win32 API calls to talk to a USB device (like my previous MFC code), and all this works fine with a 32-bit installation of Windows Vista or 7, but when I am trying to run the same code on a 64 bit installation, it fails. Even if I try to create a dedicated 64-bit application, it still does not work.
I am sure that the problem is how the marshal passes parameters (on the stack?) To the Win32 API, but my knowledge and experience of .Net / C # at this stage is not very good, to understand exactly what the problem is and how to solve it - the problem is probably more developed than the level I'm in now.
Everything seems to work fine in the code until I get to the instructions ...
while (SetupDiEnumDeviceInterfaces(hInfoSet, 0, ref gHid, (uint)nIndex, ref oInterface))
SetupDI... true 32- USB-, false 64- . , , , , API Win32, , . DLLImport :
[DllImport("setupapi.dll", SetLastError = true)] protected static extern bool SetupDiEnumDeviceInterfaces(IntPtr lpDeviceInfoSet, uint nDeviceInfoData, ref Guid gClass, uint nIndex, ref DeviceInterfaceData oInterfaceData);
, - , ?
, , , !