In my C# code I am trying to use C++ functions: CM_Locate_DevNodeW and CM_Open_DevNode_Key (using pinvoke).
My code seems something like this:
String deviceId = "PCI\\VEN_8086&DEV_591B&SUBSYS_22128086&REV_01\\3&11583659&0&10";
int devInst = 0;
cmStatus = CM_Locate_DevNodeW(&devInst, deviceId, CM_LOCATE_DEVNODE_NORMAL);
if (cmStatus == CR_SUCCESS)
{
UIntPtr pHKey = new UIntPtr();
cmStatus = CM_Open_DevNode_Key(devInst, KEY_ALL_ACCESS, 0, RegDisposition_OpenExisting, pHKey, CM_REGISTRY_SOFTWARE);
if (cmStatus == CR_SUCCESS)
{
//but here cmStatus=3 (Invalid Pointer)
}
}
After calling to CM_Locate_DevNodeW, the devInst becomes 1, and the cmStatus is 0 = CR_SUCCESS. But the call to CM_Open_DevNode_Key fails.
I don't know if CM_Locate_DevNodeW returns CR_SUCCESS but puts incorrect data within devInst? ('1' does not seems like real device instance handle...)
Or maybe the call to CM_Open_DevNode_Key is wrong?
I declared the functions like this:
[DllImport("cfgmgr32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern unsafe int CM_Locate_DevNodeW(
int* pdnDevInst,
string pDeviceID,
ulong ulFlags);
[DllImport("cfgmgr32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern unsafe int CM_Open_DevNode_Key(
int dnDevNode,
int samDesired,
int ulHardwareProfile,
int Disposition,
IntPtr phkDevice,
int ulFlags);
Any help would be appreciated!
CM_Locate_DevNodeWisn't aC++function. It's aCfunction provided by the Windows API.