![]() | ReadNumber |
Reads numeric data from a device.
virtual HRESULT ReadNumber(double* pValue, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override; virtual HRESULT ReadNumber(float* pValue, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override; virtual HRESULT ReadNumber(long* pValue, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override; virtual HRESULT ReadNumber(short* pValue, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override; virtual HRESULT ReadNumber(BYTE* pValue, bool bFlush = true, long lTimeout = CUR_TIMEOUT) override;
[out] Number read from the device.
[in] If true, the formatted I/O read buffer is flushed.
[in] I/O timeout value in milliseconds.
Returns S_OK if successful, otherwise a failure HRESULT.
The ReadNumber function reads string data the formatted I/O read buffer and converts it to a number. Integers are converted in the base specified.
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.
If the device response string cannot be converted into the numeric type requested, this function returns an error.
For more precise control of the response formatting and conversion, use the Scanf function.
The following example demonstrates use of the ReadNumber function.
// CoAcme4321.cpp STDMETHODIMP Acme4321::IAcme4321_get_Count(long* plCount) { HRESULT hr = S_OK; hr = io.ReadNumber(plCount); return hr; }