阅读:1564回复:8
debug出现错误
我的程序每次debug到下面代码时,就会提示说指令引用的内存不能为write.但事实上我的outBuffer指向的一个数组的起始地址,应该不存在指针错误。
bResult = DeviceIoControl (hOutDevice, IOCTL_EZUSB_BULK_WRITE, &OutBulkControl, sizeof(BULK_TRANSFER_CONTROL), outBuffer, OutPacketSize, 0, NULL); 大侠们帮忙看一下,可能是什么原因导致的? 谢谢! |
|
沙发#
发布于:2005-03-08 13:24
要把上下文贴出来才行。
|
|
|
板凳#
发布于:2005-03-08 13:57
要把上下文贴出来才行。 UINT WriteProc( LPVOID ) { BOOLEAN bResult; short outBuffer[512]; ULONG OutPacketSize; if (WriteLength()>=MAX_BUFFER_SIZE) { OutPacketSize=MAX_BUFFER_SIZE; } else { OutPacketSize=WriteLength(); } WriteCompleteEvent=CreateEvent(0,FALSE,FALSE,NULL); BULK_TRANSFER_CONTROL OutBulkControl; if (bOpenDriver (&hOutDevice) != TRUE) { AfxMessageBox(\"Failed to open the device\",MB_OK); hOutDevice = NULL; } OutBulkControl.pipeNum=0; if (hOutDevice != NULL) { for (int i=0;i<OutPacketSize;i++) outBuffer = WriteDeQueue (); bResult=DeviceIoControl(hOutDevice, IOCTL_EZUSB_BULK_WRITE, &OutBulkControl, sizeof(BULK_TRANSFER_CONTROL), outBuffer, OutPacketSize, 0, NULL); if (WriteCompleteEvent) SetEvent(WriteCompleteEvent); suswrite=1; CloseHandle(hOutDevice); } return bResult; } 上面是辅助线程函数,下面是主程序: CWinThread* myWriteThread = AfxBeginThread (WriteProc,NULL,THREAD_PRIORITY_HIGHEST,0,0,NULL); 每次debug运行到DeviceIoControl()时就会提示指令引用的内存不能为write?. ddp大家帮帮忙,这程序到底错在哪里? 我自己是怎么了看不出来了。 [编辑 - 3/8/05 by drive] [编辑 - 3/8/05 by drive] [编辑 - 3/8/05 by drive] |
|
地板#
发布于:2005-03-08 15:48
outBuffer = WriteDeQueue ();
返回什么东西?? 你改变了指针,谁知道outBuffer是多少??? |
|
|
地下室#
发布于:2005-03-08 15:50
for (int i=0;i<OutPacketSize;i++)
outBuffer [] = WriteDeQueue (); 可能还好理解点..... [编辑 - 3/8/05 by wowocock] |
|
|
5楼#
发布于:2005-03-08 18:22
哦,这是我在把程序贴过来的时候误删了。
我的程序是for (int i=0;i<OutPacketSize;i++) outBuffer(i) = WriteDeQueue (); 其中的outBuffer(i)其实是方括号,奇怪用方括号就显示不出来了。 [编辑 - 3/8/05 by drive] |
|
6楼#
发布于:2005-03-09 09:46
bResult = DeviceIoControl (hOutDevice,
IOCTL_EZUSB_BULK_WRITE, &OutBulkControl, sizeof(BULK_TRANSFER_CONTROL), outBuffer, OutPacketSize, &RetVal, NULL); |
|
|
7楼#
发布于:2005-03-09 11:08
函数调用不对,应该如下:
bResult = DeviceIoControl (hOutDevice, IOCTL_EZUSB_BULK_WRITE, &OutBulkControl, sizeof(BULK_TRANSFER_CONTROL), outBuffer, &OutPacketSize, //应该传送地址 0, NULL); |
|
|
8楼#
发布于:2005-03-09 11:12
不好意思,上面的发错了,应该如下:
bResult = DeviceIoControl (hOutDevice, IOCTL_EZUSB_BULK_WRITE, &OutBulkControl, sizeof(BULK_TRANSFER_CONTROL), outBuffer, OutPacketSize, &OutPacketSize,//该参数不能为空 NULL); |
|
|