Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Anyone can help me about this sample : mscomm32.ocx

Status
Not open for further replies.

youssef

Programmer
Mar 13, 2001
96
BE
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);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top