Click or drag to resize

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;
Parameters
pValue

[out] Number 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

Returns S_OK if successful, otherwise a failure HRESULT.

Remarks

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.

Example

The following example demonstrates use of the ReadNumber function.

C++
// CoAcme4321.cpp
STDMETHODIMP Acme4321::IAcme4321_get_Count(long* plCount)
{
  HRESULT hr = S_OK;

  hr = io.ReadNumber(plCount);

  return hr;
}
See Also

Download a complete CHM version of this documentation here.