gongrh163
驱动牛犊
驱动牛犊
  • 注册日期2003-02-20
  • 最后登录2005-09-06
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1190回复:2

请教pipe handle

楼主#
更多 发布于:2003-04-12 12:11
各位大侠,请问usb中的pipe handle是如何得到的,详细解释一下,
谢谢
jinghuiren
驱动巨牛
驱动巨牛
  • 注册日期2002-06-01
  • 最后登录2008-10-27
  • 粉丝0
  • 关注0
  • 积分291分
  • 威望460点
  • 贡献值0点
  • 好评度428点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-04-13 12:36
在论坛里用关键词USBD_ParseConfigurationDescriptorEx搜索一下,你会有收获的。
cquwyb
驱动牛犊
驱动牛犊
  • 注册日期2002-05-10
  • 最后登录2010-10-23
  • 粉丝0
  • 关注0
  • 积分160分
  • 威望16点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
板凳#
发布于: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;//&Icirc;&ordf;&Aacute;&Euml;&Igrave;&oslash;&sup3;&ouml;while
}
else
 free(functionClassDeviceData);
}//if
else
if(ERROR_NO_MORE_ITEMS == GetLastError())
{
found=FALSE;
break;
}
   }//while
  SetupDiDestroyDeviceInfoList (hardwareDeviceInfo);
  return found;
}

USBclass::~USBclass()
{
}

  谢谢指教  
HonestTreee
游客

返回顶部