阅读:1462回复:0
求助帖!我是个菜鸟,现在有个关于ReadFile的问题,求解答
小弟是个本科生,正在做毕业设计,原来没怎么接触过驱动方面的编程,老师让我做一个能捕获USB设备通讯的软件(类似BUS HOUND,功能不用那么全面)。我在网上查了些资料,但是执行到READFILE时总是有错误,错误写的是XXXX指令引用XXX内存。该内存不能为written,希望有高人能指点下,谢谢!
============================================================================== 这块是扫描USB设备时得到的信息,我在ONSHOW中对设备名的赋值是否也存在问题?求指教 ============================================================================== 查找所有USB设备: 找到USB控制器:1 USB控制器:{36FC9E60-C465-11CF-8056-444553540000}\0002 USB控制器名称:HCD0 USB Hub名称: USB#ROOT_HUB#4&13a97026&1#{f18a0e88-c30c-11d0-8815-00a0c906bed8} 第1端口有USB设备连接 状态:已连接! 连接设备名:{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}\0002 connection index:[Port:1] Device class:0x0, idVendor:0x46D, idProduct:0xC018, iManufacturer:0x1, iSerialNumber:0x0, bus speed:low, Device Address:0x1, Open Pipes:0x1 第2端口没有USB设备联接 ============================================================================== void CTestUSBDlg::OnShow() { CString strShow; PCHAR HCName="USB#ROOT_HUB20#4&1ffcc331&1#{f18a0e88-c30c-11d0-8815-00a0c906bed8}"; PCHAR deviceName; HANDLE hHCDev; LPDWORD lpNumberOfBytesRead; char Buffer[1024]; DWORD result,s,BufferLen=1024; memset(Buffer,0,sizeof(Buffer)); deviceName=(PCHAR)malloc(strlen(HCName)+sizeof("\\\\.\\")); strcpy(deviceName,"\\\\.\\"); strcpy(deviceName+sizeof("\\\\.\\")-1,HCName); hHCDev=CreateFile(deviceName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if(hHCDev!=INVALID_HANDLE_VALUE) { strShow.Format("hello!\r\n"); ShowMessage(strShow); ReadFile(hHCDev, Buffer, BufferLen, lpNumberOfBytesRead, 0); } else {strShow.Format("错误!\r\n"); ShowMessage(strShow);} CloseHandle(hHCDev); } |
|