Hi,
I have a C# application that needs to get the list of a connected devices. The actual operation is done by a 3rd party DLL.
The program works in Win7 and Vista, however for XP, the call always returns zero (0) number of devices connected, in structure field NumDevices.
The code was built in VS2008, Framework 3.5.
Can anyone help in resolving this or point me to sources/articles/KB detailing any differences between XP and Win7 C# development.
Here's the C# code that calls that DLL.
[DllImport(BSApi.BSAPI)]
public static extern int ABSEnumerateDevices(
string pszEnumDsn,
ref IntPtr ppDeviceList);
The ppDeviceList is a pointer to a structure containing the list of devices returned by the dll call.
[StructLayout(LayoutKind.Sequential)]
unsafe public struct ABS_DEVICE_LIST
{
public UInt32 NumDevices;
[MarshalAs(UnmanagedType.ByValArray)]
public ABS_DEVICE_LIST_ITEM[] List; }
Below is the structure for the ABS_DEVICE_LIST_ITEM
[StructLayout(LayoutKind.Sequential)]
unsafe public struct ABS_DEVICE_LIST_ITEM
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)]
public byte[] DsnSubString;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)]
public byte[] reserved; }
We call the dll function as follows:
int rc = 0;
BSTypes.ABS_DEVICE_LIST deviceList = new BSTypes.ABS_DEVICE_LIST();
int rawSize = Marshal.SizeOf(deviceList);
IntPtr buffer = Marshal.AllocHGlobal(rawSize);
Marshal.StructureToPtr(deviceList, buffer, false);
rc = BSApi.ABSEnumerateDevices("usb", ref buffer);
BSApi.ABSFree(buffer);
deviceList = (BSTypes.ABS_DEVICE_LIST)Marshal.PtrToStructure(buffer,
typeof(BSTypes.ABS_DEVICE_LIST));
int count = (int)deviceList.NumDevices;