Click here to Skip to main content
15,941,973 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:

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.

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.

unsafe public struct ABS_DEVICE_LIST
    public UInt32 NumDevices;     ///Number of devices in the list

    public ABS_DEVICE_LIST_ITEM[] List;     ///The list of devices.

Below is the structure for the ABS_DEVICE_LIST_ITEM

unsafe public struct ABS_DEVICE_LIST_ITEM
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)]
    public byte[] DsnSubString;     ///device name

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)]
    public byte[] reserved;     ///Reserved for future use.

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);


deviceList = (BSTypes.ABS_DEVICE_LIST)Marshal.PtrToStructure(buffer,

int count = (int)deviceList.NumDevices;
Updated 23-Sep-10 21:39pm
CPallini 24-Sep-10 3:22am    
Removed the boldface stuff.
knockNrod 1-Oct-10 13:48pm    
I assume the biometric reader is actually functioning in XP? I'm not aware of any differences in marshalling, so I'm wondering if the problem isn't that it's empty before you copy.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900