Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SetupDiEnumDeviceInterfaces not Working.

SetupDiEnumDeviceInterfaces not Working.

Scheduled Pinned Locked Moved C / C++ / MFC
sharepointdatabasewindows-adminhelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    002comp
    wrote on last edited by
    #1

    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 value

    SP\_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
    
    0 1 Reply Last reply
    0
    • 0 002comp

      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 value

      SP\_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
      
      0 Offline
      0 Offline
      002comp
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • 0 002comp

        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.

        A Offline
        A Offline
        Albert Holguin
        wrote on last edited by
        #3

        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).

        0 1 Reply Last reply
        0
        • A Albert Holguin

          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).

          0 Offline
          0 Offline
          002comp
          wrote on last edited by
          #4

          Thanks A Lot For Reply. I got the printer by matching Product Id And Vendor ID. Y

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups