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_DevNode_Status (setupapi)
 
.
Summary
This method retrieves the status of a device instance from its device node (devnode) in the local machine's device tree.
Summary
TODO - a short description

C# Signature:

// devInst is an uint32 - this matters on 64-bit
[DllImport("cfgmgr32.dll", SetLastError=true)]
static extern int CM_Get_DevNode_Status(out UInt32 status, out UInt32 probNum, UInt32 devInst, int flags);

VB Signature:

<DllImport("cfgmgr32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _

    Private Shared Function CM_Get_DevNode_Status(ByRef status As ULong, ByRef probNum As ULong, ByVal devInst As IntPtr, ByVal Flag As Integer) As Integer
    End Function

User-Defined Types:

static readonly int CR_SUCCESS = 0x00000000;

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

The return type is either int or uint.

Tips & Tricks:

Please add some!

Sample Code:

If CM_Get_DevNode_Status(status, problem, DeviceInfoData.DevInst, 0) = CR_SUCCESS Then
        Dim sbDesc As New StringBuilder("")
        Dim MAX_LEN As Integer = 512
        Dim propRegDataType As Integer = 0
        sbDesc.Capacity = MAX_LEN
        Dim reqSize As Integer = 0
        SetupDiGetDeviceRegistryProperty(NewDeviceInfoSet, DeviceInfoData, DirectCast(SPDRP_FRIENDLYNAME, Integer), propRegDataType, sbDesc, MAX_LEN, reqSize)
        If sbDesc.ToString() = "" Then
            SetupDiGetDeviceRegistryProperty(NewDeviceInfoSet, DeviceInfoData, DirectCast(SPDRP_DEVICEDESC, Integer), propRegDataType, sbDesc, MAX_LEN, reqSize)
        End If
        If sbDesc.ToString() = "" Then
            sbDesc.Append("Unknown Description")
        End If
        Dim sbHWID As New StringBuilder("")

        sbHWID.Capacity = MAX_LEN
        SetupDiGetDeviceRegistryProperty(NewDeviceInfoSet, DeviceInfoData, DirectCast(SPDRP_HARDWAREID, Integer), propRegDataType, sbHWID, MAX_LEN, reqSize)
        Dim scanResult As New ScanResults(sbHWID.ToString(), sbDesc.ToString())
        Console.WriteLine("Device Detected: {0} - {1}", sbDesc.ToString(), sbHWID.ToString())

        Dim deviceInstallParams As New SP_DEVINSTALL_PARAMS()
        deviceInstallParams.cbSize = Marshal.SizeOf(GetType(SP_DEVINSTALL_PARAMS))
        SetupDiGetDeviceInstallParams(NewDeviceInfoSet, DeviceInfoData, deviceInstallParams)
        deviceInstallParams.DriverPath = "D:\STK1160_AVStream_ATV_20070831"
        If Not SetupDiBuildDriverInfoList(NewDeviceInfoSet, DeviceInfoData, SPDIT_COMPATDRIVER) Then
            Dim eCode As Integer = Marshal.GetLastWin32Error()
            Console.WriteLine(vbTab & "Error Building Driver Info List. Code: {0}", eCode)
        End If
        Dim memIndex As Integer = 0
        Dim drvErr As Integer = 0
        Dim drvData As New SP_DRVINFO_DATA()
        drvData.cbSize = Marshal.SizeOf(GetType(SP_DRVINFO_DATA))
        Dim enumResult As Boolean = SetupDiEnumDriverInfo(NewDeviceInfoSet, DeviceInfoData, SPDIT_COMPATDRIVER, memIndex, drvData)
        If Not enumResult Then
            drvErr = Marshal.GetLastWin32Error()
            Console.WriteLine(vbTab & "Error Enumerating Driver Info. Code: {0}", drvErr)
        End If
        'While enumResult AndAlso drvErr <> ERROR_NO_MORE_ITEMS

        '    System.Math.Max(System.Threading.Interlocked.Increment(memIndex), memIndex - 1)
        '     End While
        SetupDiDestroyDriverInfoList(NewDeviceInfoSet, DeviceInfoData, SPDIT_COMPATDRIVER)
        End If

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
Edit This Page
Find References
Show Printable Version
Revisions