Prev: WinUsb_GetOverlappedResult() with asynchronous call to WinUsb_ReadPipe()
Next: Programming an auto power-on timer
From: J.R. Heisey J.R. on 7 Apr 2010 11:53 Greetings, Apparently post to this group with Outlook Express does not work anymore. I could not find a group that was specific to Microsoft's WinUsb driver. Please refer me. * Using a background thread to process packets from the interrupt endpoint. * Background thread calls WinUsb_ReadPipe() then waits on the passed in event object. * On returning from the wait function my ReadCompletion() function is called. Function is below. * This code is implemented in a native x86 DLL. * When this DLL is used by a particular in-house DotNet application the buffer m_InterruptReadBuffer does not contain the data even though m_uInterruptReadCount contains the data length. * Does not appear to happen when executing from a native x86 application. * Note the use of two buffers. * I would like an explanation and how to correct this behavior so that I don't need the hack code. Anyone from Microsoft listening? Thanks, J.R. Heisey Synaptic, Inc. Lead Software Engineer void InterruptReadCompletion() { if (WinUsb_GetOverlappedResult(m_usbHandle, &m_ovInterruptRead, &m_uInterruptReadCount[m_uInterruptBufferIndex], TRUE)) { DWORD uBufferIndex = m_uInterruptBufferIndex; // hack that works because data is aways ASCII while (m_InterruptReadBuffer[uBufferIndex] == 0) { // Need this wait loop because the buffer does not contain the data on return of WinUsb_GetOverlappedResult() } // Swap buffer so we can get the next on started during the dispatch. m_uInterruptBufferIndex = m_uInterruptBufferIndex == 1 ? 0 : 1; InterruptReadBegin(); // calls WinUsb_ReadPipe() again. // using two buffers else the single buffer can get corrupted after this point if (m_uInterruptReadCount[uBufferIndex] != 0) { DispatchInterruptCallback((char *)&m_InterruptReadBuffer[uBufferIndex][0], m_uInterruptReadCount[uBufferIndex]); } } } |