Click or drag to resize

LowLevelReadString

Reads raw bytes directly from a device without going through the formatted I/O read buffer and returns the results as a string.

virtual HRESULT LowLevelReadString(CString& pBuf, long cchDesired, long lTimeout = CUR_TIMEOUT)  override;

virtual HRESULT LowLevelReadString(BSTR* pBuf, long cchDesired, long lTimeout = CUR_TIMEOUT) override;
Parameters
pBuf

[out] String read from the device.

cchDesired

[in] Number of bytes to read from the device.

lTimeout

[in] I/O timeout value in milliseconds.

Return Value

Returns S_OK if successful, otherwise a failure HRESULT.

Remarks

Unlike the buffered I/O functions, such as Queryf, ReadReadNumber, etc., the LowLevelReadString function reads raw bytes directly from the device, rather than going through formatted I/O read buffer.

Caution note Caution

It is critical that these low-level functions not be intermixed with buffered I/O functions in a sequence of operations, such as a set of calls implementing a single driver method. The buffered I/O functions assume that all data read from or sent to the device passes through the I/O buffer, and intermixing these calls with low-level functions that directly access the device can produce incorrect results and/or I/O errors.

Example

The following example demonstrates use of the LowLevelReadString function.

C++
// CoAcme4321.cpp
STDMETHODIMP Acme4321::IAcme4321_QueryName(BSTR* pbstrName)
{
  HRESULT hr = S_OK;

  // Read up to 50 bytes and return as a BSTR
  hr = io.LowLevel.LowLevelReadString(pbstrName, 50);

  return hr;
}
See Also

Download a complete CHM version of this documentation here.