Click to See Complete Forum and Search --> : MSComm control


Rune Wemberg
April 25th, 1999, 06:39 AM
I am trying to send binary data through a serial port
using MS communication Control v5.0. The control uses
the VARIANT structure for passing data. I have problems
with sending an array of unsigned chars with the VARIANT
data type. Anyone tried sending binary data using this
control. I have been looking at the VCTERM example, but
it only supports ASCII.

Rune Wemberg

Emanuil Achim
May 17th, 1999, 04:40 AM
Hi !

You must use SAFEARRAYs. It's look like:
pMSComm->InputMode = comInputModeBinary;
VARIANT var;

VariantInit ( &var );
var.vt = VT_ARRAY | VT_UI1;

SAFEARRAY* pSA;
SAFEARRAYBOUND bounds = {4, 0};
pSA = SafeArrayCreate ( VT_UI1, 1, &bounds);

unsigned char* ucArray;
SafeArrayAccessData (pSA, (void**)&ucArray);
ucArray [0] = 'A';
ucArray [1] = 'B';
ucArray [2] = 'C';
ucArray [3] = 'D';

SafeArrayUnaccessData (pSA);
var.parray = pSA;

pMSComm->Output = var;

Hope it helps.
Emanuil