本文介绍了如何发送U盘U盘控制权转让?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人:
我想为U盘发送usb控制传输,在busHound中我们可以发送usb控制传输,但是我不知道如何用VC11发送它,我从msdn找到了一些有关CTL的信息.下面是我的测试源代码.

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.

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;
	}



现在我可以获取我的U盘设备句柄,但是没有获取接口句柄,GetLastError()函数返回ERROR_NOT_ENOUGH_MEMORY值.这对我来说很紧急,如果您能给我们一些建议,我先感谢您,谢谢.



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.

推荐答案



这篇关于如何发送U盘U盘控制权转让?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 05:18