CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: MSComm control

  1. #1
    Join Date
    Apr 1999
    Posts
    3

    MSComm control

    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


  2. #2
    Join Date
    May 1999
    Posts
    13

    Re: MSComm control

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured