[out] Single character read from the device.
Read
Reads data from a device.
Syntax
Section titled “Syntax”virtual HRESULT Read(char& ch, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override;
virtual HRESULT Read(BYTE* pBuf, long cbDesired, long* pcbActual, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override;
virtual HRESULT Read(SAFEARRAY** pBuf, long cbDesired, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override;Parameters
Section titled “Parameters”ch
pBuf
[out] Array of bytes read from the device.
cbDesired
[in] Number of elements (bytes) to read from the device.
pcbActual
[out] Actual number of elements (bytes) read from the device.
bFlush
[in] If true, the formatted I/O read buffer is flushed.
lTimeout
[in] I/O timeout value in milliseconds.
Return value
Section titled “Return value”Returns S_OK if successful, otherwise a failure HRESULT.
Remarks
Section titled “Remarks”The Read function reads raw bytes from the formatted I/O read buffer. If the bFlush parameter is true, then the contents of the I/O read buffer are flushed. Flushing the read buffer ensures no unintentional data remains in the buffer for subsequent reads.
Example
Section titled “Example”The following example demonstrates use of the Read function.
STDMETHODIMP Acme4321::IAcme4321_QueryData(SAFEARRAY** ppsaData){ HRESULT hr = S_OK;
// Read 1000 bytes. Type of elements is automatically determined from the type of the ppsaData SAFEARRAY parameter hr = io.Read(ppsaData, 1000);
return hr;}