CM_Get_DevNode_Property (cfgmgr32)
Last changed: -109.42.113.142

.
Summary
Retrieves a device instance property.

C# Signature:

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType, [Out]byte[] propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x02, out sbyte propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x03, out byte propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x04, out short propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x05, out ushort propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x06, out int propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x07, out uint propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x08, out long propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x09, out ulong propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x0A, out float propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x0B, out double propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x0C, out decimal propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x0D, out Guid propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x11, [MarshalAs(UnmanagedType.I1)] out bool propertyBuffer,
    ref uint propertyBufferSize, uint zeroFlags);

[DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
private static extern ConfigManagerResult CM_Get_DevNode_Property(uint devInst, ref DEVPROPKEY propertyKey,
    out uint propertyType_0x12, StringBuilder propertyBuffer, ref uint propertyBufferSize, uint zeroFlags);

User-Defined Types:

struct DEVPROPKEY {
     public DEVPROPKEY(Guid guid, uint pid) {
     _guid = guid;
     _pid = pid;
     }
     public Guid _guid;
     public uint _pid;
}

enum ConfigManagerResult : uint {
     Success = 0x00000000,
     Default = 0x00000001,
     OutOfMemory = 0x00000002,
     InvalidPointer = 0x00000003,
     InvalidFlag = 0x00000004,
     InvalidDevnode = 0x00000005,
     InvalidDevinst = InvalidDevnode,
     InvalidResDes = 0x00000006,
     InvalidLogConf = 0x00000007,
     InvalidArbitrator = 0x00000008,
     InvalidNodelist = 0x00000009,
     DevnodeHasReqs = 0x0000000A,
     DevinstHasReqs = DevnodeHasReqs,
     InvalidResourceid = 0x0000000B,
     NoSuchDevnode = 0x0000000D,
     NoSuchDevinst = NoSuchDevnode,
     NoMoreLogConf = 0x0000000E,
     NoMoreResDes = 0x0000000F,
     AlreadySuchDevnode = 0x00000010,
     AlreadySuchDevinst = AlreadySuchDevnode,
     InvalidRangeList = 0x00000011,
     InvalidRange = 0x00000012,
     Failure = 0x00000013,
     NoSuchLogicalDev = 0x00000014,
     CreateBlocked = 0x00000015,
     RemoveVetoed = 0x00000017,
     ApmVetoed = 0x00000018,
     InvalidLoadType = 0x00000019,
     BufferSmall = 0x0000001A,
     NoArbitrator = 0x0000001B,
     NoRegistryHandle = 0x0000001C,
     RegistryError = 0x0000001D,
     InvalidDeviceId = 0x0000001E,
     InvalidData = 0x0000001F,
     InvalidApi = 0x00000020,
     DevloaderNotReady = 0x00000021,
     NeedRestart = 0x00000022,
     NoMoreHwProfiles = 0x00000023,
     DeviceNotThere = 0x00000024,
     NoSuchValue = 0x00000025,
     WrongType = 0x00000026,
     InvalidPriority = 0x00000027,
     NotDisableable = 0x00000028,
     FreeResources = 0x00000029,
     QueryVetoed = 0x0000002A,
     CantShareIrq = 0x0000002B,
     NoDependent = 0x0000002C,
     SameResources = 0x0000002D,
     NoSuchRegistryKey = 0x0000002E,
     InvalidMachinename = 0x0000002F,   // NT ONLY
     RemoteCommFailure = 0x00000030,   // NT ONLY
     MachineUnavailable = 0x00000031,   // NT ONLY
     NoCmServices = 0x00000032,   // NT ONLY
     AccessDenied = 0x00000033,   // NT ONLY
     CallNotImplemented = 0x00000034,
     InvalidProperty = 0x00000035,
     DeviceInterfaceActive = 0x00000036,
     NoSuchDeviceInterface = 0x00000037,
     InvalidReferenceString = 0x00000038,
     InvalidConflictList = 0x00000039,
     InvalidIndex = 0x0000003A,
     InvalidStructureSize = 0x0000003B
}

Sample Code:

DEVPROPKEY key = ...;
uint propertyType;
uint propBufSize = 0;
byte[] buffer = null;
result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, buffer, ref propBufSize, 0);
if (result != ConfigManagerResult.BufferSmall) {
     throw new Exception(string.Format("Failed to retrieve property size for property {0} {1}: {2}.",
     key._guid, key._pid, result));
}
object value;
switch (propertyType) {
     case 0x02:
     sbyte v;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out v, ref propBufSize, 0);
     value = v;
     break;

     case 0x03:
     byte b;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out b, ref propBufSize, 0);
     value = b;
     break;

     case 0x04:
     short s;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out s, ref propBufSize, 0);
     value = s;
     break;

     case 0x05:
     ushort us;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out us, ref propBufSize, 0);
     value = us;
     break;

     case 0x06:
     int i;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out i, ref propBufSize, 0);
     value = i;
     break;

     case 0x07:
     uint ui;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out ui, ref propBufSize, 0);
     value = ui;
     break;

     case 0x08:
     long l;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out l, ref propBufSize, 0);
     value = l;
     break;

     case 0x09:
     ulong ul;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out ul, ref propBufSize, 0);
     value = ul;
     break;

     case 0x0A:
     float f;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out f, ref propBufSize, 0);
     value = f;
     break;

     case 0x0B:
     double d;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out d, ref propBufSize, 0);
     value = d;
     break;

     case 0x0C:
     decimal dec;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out dec, ref propBufSize, 0);
     value = dec;
     break;

     case 0x0D:
     Guid guid;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out guid, ref propBufSize, 0);
     value = guid;
     break;

     case 0x11:
     bool bo;
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, out bo, ref propBufSize, 0);
     value = bo;
     break;

     case 0x12:
     var builder = new StringBuilder((int)propBufSize);
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, builder, ref propBufSize, 0);
     value = builder;
     break;

     default:
     buffer = new byte[propBufSize];
     result = CM_Get_DevNode_Property(devInst, ref key, out propertyType, buffer, ref propBufSize, 0);
     value = "a buffer";
     break;
}
if (result != ConfigManagerResult.Success) {
     throw new Exception("Failed to retrieve property: " + result + ".");
}

Console.Out.WriteLine("Property {0} {1:x} type {2:x} = {3}.", key._guid, key._pid, propertyType, value);

Documentation:

https://msdn.microsoft.com/en-us/library/windows/hardware/hh780220.aspx