Inspired by EG I am writing my own (small) piece of code in pure C/WinAPI for CyberLink Remote Controller and I have just found bug in EG's WinUsbWrapper.c.
- Code: Select all
while (TRUE)
{
WinUsb_ReadPipe(usbHandle, inPipeId, buffer, params->chunkSize, &length, &overlapped);
if (WaitForMultipleObjects(2, handles, FALSE, INFINITE)!=WAIT_OBJECT_0) goto exit;
if (!params->suppressRepeat || memcmp(buffer, oldBuffer, params->chunkSize))
SendMessage(params->notifyWnd, params->msg, length, (LPARAM) buffer);
tmpBuffer = oldBuffer;
oldBuffer = buffer;
buffer = tmpBuffer;
ResetEvent(overlapped.hEvent);
}
As you can see, the code performs overlapped read (WinUsb_ReadPipe()) and then sends pointer to the buffer and its length to "higher level". The problem is that the variable "length" sometimes contains wrong value. According to MSDN:
So in order to fix the problem call to WinUsb_GetOverlappedResult() must be added after WaitForMultipleObjects():For an overlapped operation (and if LengthTransferred is a non-NULL value), the value received in LengthTransferred after WinUsb_ReadPipe returns is meaningless until the overlapped operation has completed. To retrieve the actual number of bytes read from the pipe, call WinUsb_GetOverlappedResult.
- Code: Select all
while (TRUE)
{
WinUsb_ReadPipe(usbHandle, inPipeId, buffer, params->chunkSize, &length, &overlapped);
if (WaitForMultipleObjects(2, handles, FALSE, INFINITE)!=WAIT_OBJECT_0) goto exit;
WinUsb_GetOverlappedResult(usbHandle, &overlapped, &length, FALSE);
if (!params->suppressRepeat || memcmp(buffer, oldBuffer, params->chunkSize))
SendMessage(params->notifyWnd, params->msg, length, (LPARAM) buffer);
tmpBuffer = oldBuffer;
oldBuffer = buffer;
buffer = tmpBuffer;
ResetEvent(overlapped.hEvent);
}
Now "length" contains proper value.
However there is also problem in Python code (<EG ROOT DIR>\plugins\CyberlinkUniversalRemote\__init__.py). It seems that the author assumed that all RC codes have have fixed length (4 bytes) what seems not to be true. This causes strange EventGhost's behaviour, eg. DVDMenu key sometimes works and sometimes doesn't. It is easy to explain: WinUsb_GetOverlappedResult() returns 3 as the length but when one attempts to read 4 bytes from the buffer then 04h 00h 04h 00h or 04h 00h 04h 02h is read. I hope it helps.
