Skip to content

Instantly share code, notes, and snippets.

@KunYi
Created March 13, 2020 05:29
Show Gist options
  • Save KunYi/bbcde28639393fbe23426a78f58921b9 to your computer and use it in GitHub Desktop.
Save KunYi/bbcde28639393fbe23426a78f58921b9 to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <cfgmgr32.h>
int main()
{
DEVINST devParentInst = 0;
DEVINST devInst = 0;
CONFIGRET status = 0;
const DEVINSTID_W PhantomDevNode = (DEVINSTID_W)L"ROOT\\TOASTER\\0000";
const DEVINSTID_W ToasterBasicID = (DEVINSTID_W)L"TOASTER\\BASIC_TOASTER";
const DEVINSTID_W ToasterSuperID = (DEVINSTID_W)L"TOASTER\\SUPER_TOASTER";
// to get root node
status = CM_Locate_DevNode(&devParentInst, NULL, CM_LOCATE_DEVNODE_NORMAL);
if (status != CR_SUCCESS)
return -1;
// Create new Device node
status = CM_Create_DevNodeW(&devInst, PhantomDevNode, devParentInst,
CM_CREATE_DEVNODE_PHANTOM);
if (!(status == CR_SUCCESS || status == CR_ALREADY_SUCH_DEVNODE))
return -2;
status = CM_Create_DevNodeW(&devInst, PhantomDevNode, devParentInst,
CM_CREATE_DEVNODE_NORMAL);
if (!(status == CR_SUCCESS || status == CR_ALREADY_SUCH_DEVNODE))
return -3;
// append Hardware ID
CM_Add_IDW(devInst, (DEVINSTID_W)ToasterBasicID, CM_ADD_ID_HARDWARE);
CM_Add_IDW(devInst, (DEVINSTID_W)ToasterSuperID, CM_ADD_ID_HARDWARE);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment