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. |