开发者

Open device by GUID

I'm attempting to access a physical device using a software package from the vendor.

In earlier versions of the software package they had the user open the device via the DOS Symbolic name:

hDevice= CreateFile("\\\\.\\DevName", 
    GENERIC_READ | GENERIC_WRITE, 
    0, NULL, OPEN_ExiSTING, 0, NULL);

However, they released a new version which requires the device be opened by GUID and a DEFINE_GUID is included in their header. This update also disabled the old method to open the device.

They did not update their documentation to show how to open the device by GUID and I haven't been able to find anything helpful with my go开发者_JAVA百科ogle-fu.

Surely there must be an example somewhere showing how to open a device using the GUID?


Most likely the vendor gave you a 'device interface GUID'. To get a name that you can use for CreateFile(), you have to enumerate all devices with that GUID. This is done by calling SetupDiGetClassDevs() with the flag DIGCF_DEVICEINTERFACE. The resulting list is represented by a handle to a device information set (a HDEVINFO). Then you feed that handle into repeated calls to SetupDiEnumDeviceInterfaces() to walk the list. For each list item you then have to call SetupDiGetDeviceInterfaceDetail() to receive the corresponding device path.


You've probably figured it out by now, but WinObj is pretty handy for poking around the object manager namespace. Once you find the name of the object you're looking for there, it should be pretty straightforward to get the open right.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜