Home > Software engineering >  Always returns failure, HID USB, speaking, reading and writing for error code is 997, please advice
Always returns failure, HID USB, speaking, reading and writing for error code is 997, please advice

Time:10-23

USB, speaking, reading and writing, able to handle, captured by the CreateFile call WriteFile or ReadFile always returns failure, error code is 997, the following code is written to HID
If (m_hUsb==INVALID_HANDLE_VALUE) return;

Unsigned char OutputBuffer [70].
DWORD nWriteBytes;
HANDLE WriteEvent=CreateEvent (NULL, true, false, NULL);
OVERLAPPED writeOverlap;
WriteOverlap. HEvent=WriteEvent;
WriteOverlap. Offset=0;
WriteOverlap. OffsetHigh=0;

UpdateData(TRUE);
OutputBuffer [0]=0 x00;
OutputBuffer [1]=0 x01;
OutputBuffer [2]=0 x02;
OutputBuffer [3]=0 x03;
//for (int I=1; I - 1 & lt; M_SendStr. GetLength (); I++)
//{
//OutputBuffer. [I]=m_SendStr GetAt (I - 1);
////WideCharToMultiByte
//}
ResetEvent (WriteEvent);
DWORD len=m_SendStr. GetLength () + 1;
If (WriteFile (m_hUsb, & amp; OutputBuffer, 65, & amp; NWriteBytes, & amp; WriteOverlap))
{
AfxMessageBox (_T (Succ "write"));
} the else
{
DWORD Err=GetLastError ();
Cout}

O give directions, thank you

CodePudding user response:

997
Overlapped I/O operation is in progress,

If you repeat open the read and write operations, remember after each use of release,,

CodePudding user response:

The handsome boy your messaging program? Will you please pass the source? Thank you very much

CodePudding user response:

It is so, your IO is underway,
You since you enable asynchronous transmission, must be waiting for the complete!
When the WriteFile returns TRUE, said has already been completed at this time,
When the WriteFile returns FALSE, detection LastError for ERROR_IO_PENDING,
Using the GetOverlappedResult detect transmission is complete,

CodePudding user response:

Later processing the GetOverlappedResult

DWORD Err=GetLastError ();
If (Err==ERROR_IO_PENDING)
{
If (the GetOverlappedResult (m_hUsb, & amp; WriteOverlap, & amp; NWriteBytes, TRUE))
.
}

CodePudding user response:

The function you need to add "status" control mechanism, received can be read, write a successful events, can automatically into the corresponding processing,