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 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;
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 ++)
{
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 ;
}
DWORD ReqLen;
SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL);
ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char[ReqLen]);
if( ifDetail==NULL)
{
SetupDiDestroyDeviceInfoList(info);
return ;
}
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);
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.