Click here to Skip to main content
16,016,477 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear all:
I want to send usb control transfer for U disk,In busHound we can send usb control transfer,but I don't kown how to send it by VC11,I find some information about CTL from msdn.below is my test source code.
C++
static /*const*/ GUID GUID_DEVINTERFACE_USB_DEVICE = 
	{ 0xA5DCBF10L, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };
	int i;
	DWORD ErrorInfo_0 , ErrorInfo_1 ,ErrorInfo_2;
	PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail;
   // Get handle to relevant device information set
    HDEVINFO info = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
    if(info==INVALID_HANDLE_VALUE)
    {
        printf("No HDEVINFO available for this GUID\n");
        return ;
    }
	for(i = 0; i < 100; i ++)
	{
		// Get interface data for the requested instance
		SP_INTERFACE_DEVICE_DATA ifdata;
		ifdata.cbSize = sizeof(ifdata);
		if(!SetupDiEnumDeviceInterfaces(info, 0, &GUID_DEVINTERFACE_USB_DEVICE, i, &ifdata))
		{
			printf("No SP_INTERFACE_DEVICE_DATA available for this GUID instance\n");
			SetupDiDestroyDeviceInfoList(info);
			return ;
		}

		// Get size of symbolic link name
		DWORD ReqLen;
		SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL);
		ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char[ReqLen]);
		if( ifDetail==NULL)
		{
			SetupDiDestroyDeviceInfoList(info);
			return ;
		}

		// Get symbolic link name
		ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
		if( !SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail, ReqLen, NULL, NULL))
		{
			SetupDiDestroyDeviceInfoList(info);
			delete ifDetail;
			return ;
		}
		CString path = ifDetail->DevicePath;
		if(path.Find(_T("vid_19d2&pid_1257")) > 0)
		{
			MessageBox(_T("find ok"));
			break;
		}

	}

    printf("Symbolic link is %s\n",ifDetail->DevicePath);
    // Open file
    HANDLE rv = CreateFile( ifDetail->DevicePath, 
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
    if( rv==INVALID_HANDLE_VALUE) rv = NULL;

	delete ifDetail;
    SetupDiDestroyDeviceInfoList(info);

	WINUSB_INTERFACE_HANDLE interfacehandle;
	BOOL result = WinUsb_Initialize(rv, &interfacehandle);
	ErrorInfo_0 = GetLastError();
	if(ErrorInfo_0 == ERROR_INVALID_HANDLE)
		MessageBox(_T("1"));
	else if(ErrorInfo_0 == ERROR_NOT_ENOUGH_MEMORY)
		MessageBox(_T("2"));
	else if(ErrorInfo_0 == ERROR_BAD_DEVICE)
		MessageBox(_T("3"));
	if(!result)
	{
		MessageBox(_T("win usb init fail"));
		return;
	}


Now I can get my u disk device handle,but I didn't get interfacehandle,the function of GetLastError() return ERROR_NOT_ENOUGH_MEMORY value.This is urgent for me,if your give us some advice I am appreciated,thank you in advance.
Posted
Updated 20-Jun-12 5:03am
v2

Not Sure but try using Win32 Classes.May be it will work.
 
Share this answer
 
Now I could send usb control transfer to our device,but I will update my device driver,This way was not my hope,I want send usb control trasfer to our device not modify my device driver,if you have any way please tell me,thanks!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900