SetupDiEnumDeviceInterfaces not Working.
-
Hello Friends I am trying to connect to USB Printer.For that i m using Setup Calls but SetupDiEnumDeviceInterfaces is returning FALSE . Here is the Code that i m using to get DevicePath:
#define CLSID_STR_WEIUSB (L"{4d36e979-e325-11ce-bfc1-08002be10318}")
int main(int argc, char* argv[])
{
GUID DevClass; // CLSID holder for the WEIUSB device class
HDEVINFO hDevInfoSet; // Handle to device information set
DWORD dwIndex; // Index of current device info set record
DWORD dwRequired; // Required buffer length
DWORD dwError; // Error value from GetLastError()
BOOL bResult; // Boolean return result valueSP\_DEVICE\_INTERFACE\_DATA DevNode; PSP\_DEVICE\_INTERFACE\_DETAIL\_DATA DevDetails; // Convert the registry-formatted CLSID for the WEIUSB device // class to a GUID structure. CLSIDFromString(CLSID\_STR\_WEIUSB, &DevClass); // Generate the device information set. This is the actual // enumeration process. We are specifying the class GUID of // the device type we want to enumerate, in this case only // WEIUSB devices. The second argument would allow us to // constrain the enumeration to those devices attached to a // specified enumerator, or bus. We could, for example, // enumerate only those devices attached via USB. hDevInfoSet = SetupDiGetClassDevs( &DevClass, // Only get WEIUSB devices NULL, // Not specific to any bus NULL, // Not associated with any window DIGCF\_ALLCLASSES); // Make sure enumeration completed without errors. if (hDevInfoSet == INVALID\_HANDLE\_VALUE) { fprintf(stderr, "Unable to create device information set (Error 0x%08X)\\n", GetLastError()); return 1; } printf("Successfully created device information set.\\n"); // Iterate through the device info set. for (dwIndex = 0; ; dwIndex++) { // Retrieve the data from the next node index within the // device information set. DevNode.cbSize = sizeof(DevNode); bResult = SetupDiEnumDeviceInterfaces( hDevInfoSet, // Handle to device info set NULL, // Do not apply advanced filtering &DevClass, // Class of device to retrieve dwIndex, // List index of requested record &DevNode); // Pointer to structure to receive data // If the previous call failed, do not continue trying // to enumerate devices. if (!bResult) { dwError = GetLastError(); if (dwError != ERROR\_NO\_MORE\_ITEMS) { fprintf(stderr, "Error enumerating d
-
Hello Friends I am trying to connect to USB Printer.For that i m using Setup Calls but SetupDiEnumDeviceInterfaces is returning FALSE . Here is the Code that i m using to get DevicePath:
#define CLSID_STR_WEIUSB (L"{4d36e979-e325-11ce-bfc1-08002be10318}")
int main(int argc, char* argv[])
{
GUID DevClass; // CLSID holder for the WEIUSB device class
HDEVINFO hDevInfoSet; // Handle to device information set
DWORD dwIndex; // Index of current device info set record
DWORD dwRequired; // Required buffer length
DWORD dwError; // Error value from GetLastError()
BOOL bResult; // Boolean return result valueSP\_DEVICE\_INTERFACE\_DATA DevNode; PSP\_DEVICE\_INTERFACE\_DETAIL\_DATA DevDetails; // Convert the registry-formatted CLSID for the WEIUSB device // class to a GUID structure. CLSIDFromString(CLSID\_STR\_WEIUSB, &DevClass); // Generate the device information set. This is the actual // enumeration process. We are specifying the class GUID of // the device type we want to enumerate, in this case only // WEIUSB devices. The second argument would allow us to // constrain the enumeration to those devices attached to a // specified enumerator, or bus. We could, for example, // enumerate only those devices attached via USB. hDevInfoSet = SetupDiGetClassDevs( &DevClass, // Only get WEIUSB devices NULL, // Not specific to any bus NULL, // Not associated with any window DIGCF\_ALLCLASSES); // Make sure enumeration completed without errors. if (hDevInfoSet == INVALID\_HANDLE\_VALUE) { fprintf(stderr, "Unable to create device information set (Error 0x%08X)\\n", GetLastError()); return 1; } printf("Successfully created device information set.\\n"); // Iterate through the device info set. for (dwIndex = 0; ; dwIndex++) { // Retrieve the data from the next node index within the // device information set. DevNode.cbSize = sizeof(DevNode); bResult = SetupDiEnumDeviceInterfaces( hDevInfoSet, // Handle to device info set NULL, // Do not apply advanced filtering &DevClass, // Class of device to retrieve dwIndex, // List index of requested record &DevNode); // Pointer to structure to receive data // If the previous call failed, do not continue trying // to enumerate devices. if (!bResult) { dwError = GetLastError(); if (dwError != ERROR\_NO\_MORE\_ITEMS) { fprintf(stderr, "Error enumerating d
-
Hey Guys I tried by passing {A5DCBF10-6530-11D2-901F-00C04FB951ED} this GUID and It returns me all USB' devicePath. but how can I differentiate for Printer? Any Ideas ? Thanks in Advance.
There's a call (can't remember off the top of my head) that gives you more descriptive information based on the device ID (which you should be able to extract from the information above).
-
There's a call (can't remember off the top of my head) that gives you more descriptive information based on the device ID (which you should be able to extract from the information above).