ERROR_INVALID_HANDLE
-
12-11-2019 - |
Question
I am trying to use the following functions defined in mpusbapi.h
HANDLE(*MPUSBOpen)(DWORD instance, //Input
PCHAR pVID_PID, //Input identifier
PCHAR pEP, //Input pipe
DWORD dwDir, //Input
DWORD dwReserved); //Input <Future Use>
DWORD(*MPUSBWrite)(HANDLE handle, //Input
PVOID pData, //Input
DWORD dwLen, //Input
PDWORD pLength, //Output
DWORD dwMilliseconds); //Input
When I use these in my test.cpp, it looks like;
HANDLE LACOutpipe;
pipeName="\\MCHP_EP";
PCHAR VidPid="vid_04d8&pid_fc5f";
BYTE bufData[3];
DWORD buflen=sizeof(bufData);
DWORD bufProcessed;
LACOutpipe=MPUSBOpen(0, //only one device connected, dont need to check for multiple
VidPid, //this is the device driver vid and pid
pipeName, //the pipe to write to?
MP_WRITE, //MP_WRITE is just 1
0); //not supported yet?
cout<<LACOutpipe<<endl;
//now use LACOutpipe handle to write
cout<<MPUSBWRITE(LACOutpipe, //the handle to write to
bufData, //BYTE array with data to be sent
bufLen, //length of bufData
&bufProcessed, //bytes processed
10000) //10 second timeout
<<endl;
cout<<GetLastError()<<endl;
The console output is:
FFFFFFFF
0
6
Press any key to continue...
MPUSBWrite returning 0 means that the write function failed. Error code 6 corresponds to ERROR_INVALID_HANDLE: The handle is invalid.
Anyone know why? I have a hunch it is the pipeName
but not sure how to check/fix this.
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow