If anyone can help me for write a lite sample to receive binary data from serialport with the mscomm32.ocx.
I find one but I don't understand how his working ?
It is possible to explain how and where the datas is writing in wich variable.
Best regards.
////////////////////////////////////////////////
MSCOMM supports binary data, read the
documentation.
Read Microsoft KB Article ID: Q151899
Load up a CByteArray with your data, then
pass it into a COleVariant constructor,
then pass the COleVariant to SetOutput();
To receive incoming binary, set the
SetInputMode to BINARY.
Call SafeArrayGetUBound to find out the
length of the binary data, then call
SafeArrayAccessData() to get a void
pointer to the data.
However, versions of windows with DBCS (japanese, chinese windows, etc) enabled will not work properly.
Here is a sample of how to receive binary data:
(m_pHelperDlg is a pointer to my hidden dialog that contains the MSCOMM control)
COleVarient vVar = m_pHelperDlg->m_Comm.GetInput();
long lLen;
HRESULT hr = SafeArrayGetUBound(vVar.parray, 1, &lLen);
if (hr == S_OK)
{
lLen++; // upper bound is a Zero based index
char * pAccess;
hr = SafeArrayAccessData(vVar.parray, (void**)&pAccess);
if (hr == S_OK)
{
// now do stuff with pAccess[] up to lLen
SafeArrayUnaccessData(vVar.parray);
}
I find one but I don't understand how his working ?
It is possible to explain how and where the datas is writing in wich variable.
Best regards.
////////////////////////////////////////////////
MSCOMM supports binary data, read the
documentation.
Read Microsoft KB Article ID: Q151899
Load up a CByteArray with your data, then
pass it into a COleVariant constructor,
then pass the COleVariant to SetOutput();
To receive incoming binary, set the
SetInputMode to BINARY.
Call SafeArrayGetUBound to find out the
length of the binary data, then call
SafeArrayAccessData() to get a void
pointer to the data.
However, versions of windows with DBCS (japanese, chinese windows, etc) enabled will not work properly.
Here is a sample of how to receive binary data:
(m_pHelperDlg is a pointer to my hidden dialog that contains the MSCOMM control)
COleVarient vVar = m_pHelperDlg->m_Comm.GetInput();
long lLen;
HRESULT hr = SafeArrayGetUBound(vVar.parray, 1, &lLen);
if (hr == S_OK)
{
lLen++; // upper bound is a Zero based index
char * pAccess;
hr = SafeArrayAccessData(vVar.parray, (void**)&pAccess);
if (hr == S_OK)
{
// now do stuff with pAccess[] up to lLen
SafeArrayUnaccessData(vVar.parray);
}