Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

CM_Get_Device_ID_List_Size (setupapi)
 
.
Summary

C# Signature:

[DllImport("setupapi.dll")]

static extern int CM_Get_Device_ID_List_Size(ref uint idListlen, int dnDevInst, uint ulFlags);

VB Signature:

Declare Function CM_Get_Device_ID_List_Size Lib "setupapi.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)

{

    int limit = rawData.Length;     // Set Max
    int idx = 0;
    List<string> strings = new List<string>();
    bool processing = (idx < limit);

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

    if (begx < limit)
    {
        int sz = (begx - idx);
        byte[] bytes = new byte[sz];
        Array.Copy(rawData, idx, bytes, 0, sz);
        try
        {
        string str = Encoding.Default.GetString(bytes);
        if (!string.IsNullOrEmpty(str.Trim()))
        {
            strings.Add(str);
        }
        idx = begx + 1;
        processing = (idx < limit);
        }
        catch (Exception e)
        {
        // Not sure what to do here...
        Console.WriteLine(e);
        processing = false;
        }
    }
    }

    return strings;

}

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions