CM_Get_Device_ID_List (cfgmgr32)
Last changed: -80.254.169.201

.
Summary
TODO - a short description

C# Signature:

[DllImport("setupapi.dll", SetLastError = true)]
static extern int CM_Get_Device_ID_List(string filter, byte[] bffr, uint bffrLen, uint ulFlags);

VB Signature:

Declare Function CM_Get_Device_ID_List Lib "cfgmgr32.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

const ulong CM_GETIDLIST_FILTER_PRESENT = 0x00000100;

uint idListLen = 0;
string filter = null;
List<string> deviceInstanceIdStrs = new List<string>();

int cmRet = CM_Get_Device_ID_List_Size(ref idListLen, 0, (uint)CM_GETIDLIST_FILTER_PRESENT);
if (0 == cmRet)
{
    byte[] data = new byte[idListLen];
    cmRet = CM_Get_Device_ID_List(filter, data, idListLen, (uint)CM_GETIDLIST_FILTER_PRESENT);
    if (0 == cmRet)
    {
    deviceInstanceIdStrs = BytesToStrings(data);
    }
}

return deviceInstanceIdStrs;

// ...

public List<string> BytesToStrings(byte[] rawData)
{
    List<string> strings = new List<string>();
    int limit = rawData.Length;
    int idx = 0;
    bool processing = (idx < limit);

    while (processing)
    {
    int x = idx;
    while (x < limit && 0 != rawData[x])
    {
    ++x;
    }

    if (x >= limit)
    {
    break;
    }

    int sz = (x - idx);
    byte[] bytes = new byte[sz];
    Array.Copy(rawData, idx, bytes, 0, sz);
    try
    {
    string str = Encoding.Default.GetString(bytes);
    strings.Add(str);
    idx = x + 1;
    }
    catch (Exception e)
    {
    Console.WriteLine(e);
    idx = limit;
    }

    processing = (idx < limit);
    }

    return strings;
}

// ...

Modified to return a list of strings instead of chars.

    public static List<string> BytesToStrings(byte[] rawData)
    {
        List<string> strings = new List<string>();
        int limit = rawData.Length;
        int idx = 0;
        bool processing = (idx < limit);
        string str = string.Empty;

        while (processing)
        {
        int x = idx;
        while (x < limit && 0 != rawData[x])
        {
            ++x;
        }

        if (x >= limit)
        {
            break;
        }

        int sz = (x - idx);
        byte[] bytes = new byte[sz];
        Array.Copy(rawData, idx, bytes, 0, sz);
        try
        {
            str += Encoding.Default.GetString(bytes);
            idx = x + 1;
            if (rawData[idx] == 0 && str != string.Empty)
            {
            strings.Add(str);
            str = string.Empty;
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            idx = limit;
        }

        processing = (idx < limit);
        }

        return strings;
    }

Documentation