[Compuware Corporation] [Compuware NuMega home page] [NuMega Lab] [teal] [DriverStudio] [Image][Image] · Home [Driver Products] Driver Technical Tips · DriverStudio More on WDM Device Interfaces · DriverBundle · Previews If you read the previous tip on WDM Device Interfaces, you may have been left · Compatibility wondering how applications actually obtain a path to a device that exports a [Downloads] · device interface. This tip shows how to do just that. Wizards First of all, you must know the class GUID for the device interface that was · Utilities registered by a device that you want to open. For example: · NT source examples static GUID MyDevInterfaceClassGuid = · VxD source { 0x5de30cc0, 0xfef7, 0x11d1, { 0xb3, 0x14, 0x0, 0xc0, 0xd1, 0x57, 0x49, 0x7d } }; examples · WDM source Next, call SetupDiGetClassDevs, which returns a handle to a device information examples set. The device information set contains information about all device interfaces [Resources] · of the class specified by the GUID. For example: Technical papers · Useful links #include · Technical tips [Support] · HDEVINFO hInfo; DWORD flags = DIGCF_DEVICEINTERFACE | DIGCF_PRESENT; Support hInfo = SetupDiGetClassDevs(&MyDevInterfaceClassGuid, NULL, NULL, flags); · Knowledge base · Problem The next step is to enumerate each of the device interfaces in the device submission information set. The routine that does this is SetupDiEnumDeviceInterfaces. You · Product can call this routine repeatedly, incrementing parameter index each timem, until registration it returns FALSE and GetLastError returns ERROR_NO_MORE_ITEMS. · Release notes [Shop NuMega] · SP_DEVICE_INTERFACE_DATA DevData; Buy it! DevData.cbSize = sizeof( SP_DEVICE_INTERFACE_DATA ); · Price list DWORD index = 0; · How to buy status = SetupDiEnumDeviceInterfaces( · Sales offices hInfo, NULL, &MyDevInterfaceClassGuid, [Y2K Compliance] index, &DevData ); [More information] Once you have successfully enumerated a device interface, you can then get detailed information about it. The information is bus or device specific, but always includes at least the pathname for opening the device with CreateFile. To get the detailed information, you call SetupDiGetInterfaceDeviceDetail. You must call this once to get the memory requirement for the buffer, and then a second time to actually get the data. For example: DWORD ReqLen; // first call to get buffer size SetupDiGetInterfaceDeviceDetail ( hInfo, &DevData, NULL, 0, &ReqLen, NULL ); PSP_INTERFACE_DEVICE_DETAIL_DATA DevDetail; DevDetail = PSP_INTERFACE_DEVICE_DETAIL_DATA(new char[ReqLen]); if ( ! DevDetail ) { // error } DevDetail->cbSize = sizeof SP_INTERFACE_DEVICE_DETAIL_DATA; // second call to actually get the data status = SetupDiGetInterfaceDeviceDetail ( hInfo, &DevData, DevDetail, ReqLen, &ReqLen, NULL ); Finally, you can call CreateFile with the path returned from SetupDiGetInterfaceDeviceDetail: if (status) { HANDLE hDev = CreateFile( DevDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); } If you are using DriverWorks, there are two new classes in version 2.0, CDeviceInterfaceClass and CDeviceInterface, which simplify these operations for applications. Back to technical tip start page. DriverCentral · DriverStudio · Free downloads · Resources · Support and Services · Shop NuMega Compuware NuMega · Tel: +1 603 578-8400 · Updated: 9 August 1999 · Problems? Contact our webmaster.