Quote:
Originally Posted by igorsk
Is this better?
Code:
struct Request {
DWORD reqNo;
DWORD reserved[2];
DWORD extralen;
};
struct Answer {
DWORD reserved[3];
DWORD dataLen;
char data[1]; //variable length
};
struct SendBuffer {
DWORD type; //0x10005 for WriteFile
DWORD reserved[2];
DWORD dataLen;
char data[1]; //variable length
};
int UsbReceiveProc(Request* request, size_t answersize, Answer* answer);
void UsbBuffFree(Answer* answer);
int UsbSendProc(Request* request, SendBuffer* buf, size_t sendsize, DWORD* bytesSent);
Every request and answer further defines the variable data part, e.g.:
Code:
struct FileOpenRequest: Request {
DWORD nPathLen;
char path[1]; //variable length
};
struct FileOpenAnswer: Asnswer {
DWORD hFile;
};
|
Couple of questions about this:
1) is the size that gets passed through for the read data just for the extra stuff; i.e. for FileOpen it would be "sizeof(FileOpenAnswer) - 16"?
2) Should the "Answer* answer" arg in UsbReceiveProc actually be "Answer** answer", i.e. something like:
Code:
FileOpenAnswer *pAns = 0;
HREF hErr = UsbReceiveProc(pReq, sizeof(FileOpenAnswer)-16, &pAns);
if (hErr == 0)
{
// do something with the answer
...
// free the answer
UsbFreeProc(pAns);
}