阅读:1190回复:2
请教pipe handle
各位大侠,请问usb中的pipe handle是如何得到的,详细解释一下,
谢谢 |
|
沙发#
发布于:2003-04-13 12:36
在论坛里用关键词USBD_ParseConfigurationDescriptorEx搜索一下,你会有收获的。
|
|
板凳#
发布于:2003-04-16 20:09
:)有点复杂,封装成了一个USBclass
#include \"stdafx.h\" #include <windows.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> #include <devioctl.h> #include <setupapi.h> #include <basetyps.h> #include <usbdi.h> class USBclass { public: virtual ~USBclass(); USBclass(LPGUID pGuid); bool SearchDev(); public: char Char_DevicePath[255]; LPGUID pGUID_Device; }; 还是容易使用的:只要传递GUID到类初始化函数中, 公共属性的Char_DevicePath就会存放有WDM的路径 strcat(你的对象.Char_DevicePath,\"\\\\\"); strcat(pDevPath,\"PIPE00\"); 打开PIPE00这样了:HANDLE hPIPE00=CreateFile(pDevPath, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, // FILE_FLAG_OVERLAPPED, 0, NULL); //////////////////////////////////////////////////// 类的实现代码: #include \"stdafx.h\" #include \"BSTest.h\" #include \"USBclass.h\" #include <windows.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> #include <devioctl.h> #include <setupapi.h> #include <basetyps.h> #include <usbdi.h> #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// //Construction/Destruction ////////////////////////////////////////////////////////////////////// USBclass::USBclass(LPGUID pGuid) { pGUID_Device=pGuid; } bool USBclass::SearchDev() { ULONG i=0; bool found=FALSE; HDEVINFO hardwareDeviceInfo; SP_INTERFACE_DEVICE_DATA deviceInfoData; PSP_INTERFACE_DEVICE_DETAIL_DATA functionClassDeviceData = NULL; ULONG predictedLength = 0; ULONG requiredLength = 0; deviceInfoData.cbSize=sizeof(SP_INTERFACE_DEVICE_DATA); hardwareDeviceInfo=SetupDiGetClassDevs(pGUID_Device, NULL, NULL, (DIGCF_PRESENT|DIGCF_DEVICEINTERFACE) ); while(!found) { if (SetupDiEnumDeviceInterfaces (hardwareDeviceInfo, 0, // We don\'t care about specific PDOs pGUID_Device, i++, &deviceInfoData)) { SetupDiGetInterfaceDeviceDetail(hardwareDeviceInfo, &deviceInfoData, NULL, // probing so no output buffer yet 0, // probing so output buffer length of zero &requiredLength, NULL); // not interested in the specific dev-node predictedLength = requiredLength; functionClassDeviceData=(PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(predictedLength); functionClassDeviceData->cbSize=sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); if (SetupDiGetInterfaceDeviceDetail( hardwareDeviceInfo, &deviceInfoData, functionClassDeviceData, predictedLength, &requiredLength, NULL)) { strcpy(Char_DevicePath,functionClassDeviceData->DevicePath); free(functionClassDeviceData); found=TRUE;//ΪÁËÌø³öwhile } else free(functionClassDeviceData); }//if else if(ERROR_NO_MORE_ITEMS == GetLastError()) { found=FALSE; break; } }//while SetupDiDestroyDeviceInfoList (hardwareDeviceInfo); return found; } USBclass::~USBclass() { } 谢谢指教 |
|
|