Click here to Skip to main content
15,887,376 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: disabele right click popup menu in win32 browser control Pin
venkatesh5286713-Feb-13 3:41
venkatesh5286713-Feb-13 3:41 
AnswerRe: disabele right click popup menu in win32 browser control Pin
Stephen Hewitt13-Feb-13 21:49
Stephen Hewitt13-Feb-13 21:49 
QuestionHow to retain row color while highlighting in Clist control Pin
HareeshaK12-Feb-13 16:33
HareeshaK12-Feb-13 16:33 
AnswerRe: How to retain row color while highlighting in Clist control Pin
Jochen Arndt12-Feb-13 22:48
professionalJochen Arndt12-Feb-13 22:48 
Questionx86 build Pin
john563212-Feb-13 3:56
john563212-Feb-13 3:56 
QuestionRe: x86 build Pin
David Crow12-Feb-13 4:49
David Crow12-Feb-13 4:49 
AnswerRe: x86 build Pin
Albert Holguin12-Feb-13 5:27
professionalAlbert Holguin12-Feb-13 5:27 
QuestionSetupDiEnumDeviceInterfaces not Working. Pin
002comp11-Feb-13 21:49
002comp11-Feb-13 21:49 
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:

C++
#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 devices (0x%08X).\n",
					dwError);
			}
			break;
		}

		// The device information data represents some device
		// flags and the class GUID associated with the device
		// instance.  The device details must be retrieved to
		// get the device path that can be used to open the
		// device.  This is a two-step process.  First the API
		// must be called with the pointer to a buffer set to
		// NULL, and the size of the buffer specified as zero.
		// This will cause the API to fail, but the API will
		// provide a value in the dwRequired argument indicating
		// how much memory is needed to store the file path.
		// The memory can then be allocated and the API called a
		// second time, specifying the pointer to the buffer and
		// the buffer size, to receive the actual device path.
		SetupDiGetDeviceInterfaceDetail(
			hDevInfoSet,  // Handle to device information set
			&DevNode,     // Specify a pointer to the current node
			NULL,         // Pointer to structure to receive path data
			0,            // Currently no space is allocated
			&dwRequired,  // Pointer to var to receive required buffer size
			NULL);        // Pointer to var to receive additional device info

		// Allocate memory required.
		DevDetails = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(dwRequired);
		if (DevDetails == NULL)
		{
			fprintf(stderr,
				"Unable to allocate memory for buffer.  Stopping.\n");
			break;
		}

		// Initialize the structure before using it.
		memset(DevDetails, 0, dwRequired);
		DevDetails->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

		// Call the API a second time to retrieve the actual
		// device path string.
		bResult = SetupDiGetDeviceInterfaceDetail(
			hDevInfoSet,  // Handle to device information set
			&DevNode,     // Pointer to current node in devinfo set
			DevDetails,   // Pointer to buffer to receive device path
			dwRequired,   // Length of user-allocated buffer
			&dwRequired,  // Pointer to arg to receive required buffer length
			NULL);        // Not interested in additional data

		if (!bResult)
		{
			// Some error occurred retrieve the device path.
			fprintf(stderr,
				"ERROR: Unable to retrieve device path (0x%08X).\n",
				GetLastError());
		}
		else
		{
			// Successfully retrieved the device path.  Go ahead
			// and print it to the console.
			printf("   %s\n", DevDetails->DevicePath);
		}

		// Deallocate memory used
		free(DevDetails);

	} 	getchar();

	return 0;
}

Class GUID, I extract it manually from registery. After that in fn SetupDiGetClassDevs,I tried DIGCF_ALLCLASSES or DIGCF_DEVICEINTERFACE + DIGCF_PRESENT.

But main prob ,m facing that after When I am calling SetupDiEnumDeviceInterfaces which is returning False.
Any ideas?

Regards
Yogesh
AnswerRe: SetupDiEnumDeviceInterfaces not Working. Pin
002comp11-Feb-13 22:10
002comp11-Feb-13 22:10 
SuggestionRe: SetupDiEnumDeviceInterfaces not Working. Pin
Albert Holguin12-Feb-13 5:30
professionalAlbert Holguin12-Feb-13 5:30 
GeneralRe: SetupDiEnumDeviceInterfaces not Working. Pin
002comp12-Feb-13 19:49
002comp12-Feb-13 19:49 
QuestionHow to control the volume Programitacally in C/C++? Pin
sravanthi peddi11-Feb-13 18:22
sravanthi peddi11-Feb-13 18:22 
AnswerRe: How to control the volume Programitacally in C/C++? Pin
Jibesh11-Feb-13 21:12
professionalJibesh11-Feb-13 21:12 
QuestionHow to change master volume programmatically? Pin
sairam47711-Feb-13 18:15
sairam47711-Feb-13 18:15 
AnswerRe: How to change master volume programmatically? Pin
Jibesh11-Feb-13 21:11
professionalJibesh11-Feb-13 21:11 
AnswerRe: How to change master volume programmatically? Pin
David Crow12-Feb-13 5:40
David Crow12-Feb-13 5:40 
Questionwin32 dialogbox Pin
venkatesh5286711-Feb-13 6:47
venkatesh5286711-Feb-13 6:47 
AnswerRe: win32 dialogbox Pin
Jibesh11-Feb-13 6:57
professionalJibesh11-Feb-13 6:57 
QuestionRe: win32 dialogbox Pin
«_Superman_»11-Feb-13 18:03
professional«_Superman_»11-Feb-13 18:03 
AnswerRe: win32 dialogbox Pin
venkatesh5286711-Feb-13 20:37
venkatesh5286711-Feb-13 20:37 
GeneralRe: win32 dialogbox Pin
«_Superman_»11-Feb-13 20:47
professional«_Superman_»11-Feb-13 20:47 
GeneralRe: win32 dialogbox Pin
venkatesh5286711-Feb-13 21:06
venkatesh5286711-Feb-13 21:06 
GeneralRe: win32 dialogbox Pin
venkatesh5286711-Feb-13 21:11
venkatesh5286711-Feb-13 21:11 
GeneralRe: win32 dialogbox Pin
«_Superman_»11-Feb-13 22:13
professional«_Superman_»11-Feb-13 22:13 
GeneralRe: win32 dialogbox Pin
venkatesh5286711-Feb-13 23:56
venkatesh5286711-Feb-13 23:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.