打印

运行出错

[复制链接]
471|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
stly|  楼主 | 2018-9-7 13:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

int GetImage(CCyUSBDevice * Camera, UCHAR ** image, int size)
{
int i;

CCyControlEndPoint * ctrlPoint = Camera -> ControlEndPt;

ctrlPoint -> Target = TGT_DEVICE;
ctrlPoint -> ReqType = REQ_VENDOR;
ctrlPoint -> Direction = DIR_TO_DEVICE;
ctrlPoint -> ReqCode = 0xa8;
ctrlPoint -> Value = 0;
ctrlPoint -> Index = 0;
PUCHAR ctrlBuf = new UCHAR;
PUCHAR buf = (PUCHAR)image;
LONG length = 0;

CCyBulkEndPoint * BulkIn = NULL;

int eptCount = Camera -> EndPointCount();

for (int i = 1; i < eptCount;  i++)
{  
bool bIn = Camera -> EndPoints -> bIn;  
bool bBulk =  (Camera -> EndPoints -> Attributes == 2);  

if (bBulk  && bIn) BulkIn = (CCyBulkEndPoint *) Camera -> EndPoints;  
   }  

int packageNum = 4;
BulkIn ->SetXferSize(size / packageNum);
LONG packageSize = size /packageNum;
if (size % packageSize) packageNum ++;

OVERLAPPED inOvLap[8];
UCHAR * inContext[8];
LONG recieveNum[8];
int totalNum= size;

for (i = 0; i <packageNum; i++) inOvLap.hEvent = CreateEvent(NULL, false, false, NULL);

for (i = 0; i < packageNum; i++)  
{
inContext = BulkIn -> BeginDataXfer(buf, packageSize, &inOvLap);
buf += packageSize;
}

ctrlPoint -> XferData(ctrlBuf, length);

for (i = 0; i < packageNum; i++)  
{

if(!BulkIn -> WaitForXfer(&inOvLap, 120))  
{  
BulkIn->Abort();
            WaitForSingleObject(inOvLap.hEvent,INFINITE);
};
}
buf = (PUCHAR)image;
for (i = 0; i < packageNum; i++)
{
BulkIn -> FinishDataXfer(buf, (LONG &) recieveNum, &inOvLap, inContext);
totalNum -= recieveNum;
CloseHandle(inOvLap.hEvent);
buf += packageSize;
}

return totalNum;
}
运行时,那句出错,提示是:Unhandled exception at 0x00414a99 in camera.exe: 0xC0000005: Access violation reading location 0x00000004.
沙发
stly|  楼主 | 2018-9-7 13:41 | 只看该作者
LONG packageSize = size /packageNum;

使用特权

评论回复
板凳
morrisk| | 2018-9-7 13:46 | 只看该作者
上面的提示是说访问了非法的位置…………

使用特权

评论回复
地板
xxmmi| | 2018-9-7 13:51 | 只看该作者
版本不一致吧

使用特权

评论回复
5
stly|  楼主 | 2018-9-7 13:55 | 只看该作者
哦,我知道了, 失误,失误

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

433

主题

7058

帖子

0

粉丝