Skip to content

WriteString

Sends data to a device.

virtual HRESULT WriteString(const CString& strData, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override;
virtual HRESULT WriteString(BSTR strData, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override;
virtual HRESULT WriteString(LPCTSTR strData, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override;

strData

[in] String data to send to the device.

bFlush

[in] If true, the formatted I/O write buffer is flushed to the device.

lTimeout

[in] I/O timeout value in milliseconds.

Returns S_OK if successful, otherwise a failure HRESULT.

The WriteString function sends string data to the formatted I/O write buffer. If the bFlush parameter is true, then the contents of the I/O write buffer are flushed to the device. If bFlush is false, then the data is queued in the write buffer until the buffer is full or a subsequent operation forces a flush. Queueing data in this fashion can improve I/O performance by reducing the number of I/O roundtrips to the device.

The following example demonstrates use of the WriteString function.

CoAcme4321.cpp
STDMETHODIMP Acme4321::IAcme4321_Configure(BSTR bstrSource1, BSTR bstrSource2, BSTR bstrSource3)
{
HRESULT hr = S_OK;
// Queue up commands in the write buffer
hr = io.WriteStringNoPoll(bstrSource1, false);
hr = io.WriteStringNoPoll(bstrSource2, false);
// Send string and flush buffer to device
hr = io.WriteString(bstrSource3);
return hr;
}