Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than setupapi, prefix the name with the module name and a period.
CM_Get_DevNode_Status (setupapi)
.
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);
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
The SetLastError API
1/26/2016 3:27:33 AM - -124.148.167.58
Click to read this page
4/6/2008 7:23:14 AM - anonymous
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).