CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 1999
    Posts
    3

    Please get this to work



    I am taking a string and breaking it down character by character and trying to send it out a port. I have no clue how

    to get it out the port though. Could someone describe in detail how and what variable to use to get it to go out the

    port. I suck at C++ because I just started so please be very explicit with instructions.

    //*******My code starts here*******

    //space is the emptiness between individual messages

    CString space(" "

    //lumps all messages into one data string to be sent out

    CString data = m_display1 + space + m_display2 + space + m_display3 + space;

    //get the length of the data string

    int length = strlen(data);

    int count = 0;

    //initializes port

    m_sendmessagesout.SetPortOpen(VARIANT_TRUE);

    //transmission loop

    while (count < length)

    {

    const struct tagVT_BSTR;

    CString transfer = data.GetAt(count);

    VT_BSTR.COleVariant(transfer);

    m_sendmessagesout.SetOutput(VT_BSTR);

    count++;

    }

    //close port

    m_sendmessagesout.SetPortOpen(VARIANT_FALSE);

    //*******My code ends here*******

  2. #2
    Join Date
    Apr 1999
    Posts
    24

    Re: Please get this to work



    Hi Bryan, it's me again!

    I was wrong about the VARIANT_BOOL stuff - the MFC wrapper does the conversion from BOOL to VARIANT_BOOL for you.

    So, where are we? I suggest you try the following:

    #include <comdef.h> // for definition of _variant_t type

    CString data("Stuff to send"

    // convert data to a VARIANT

    _variant_t var(data);

    // select COM1

    m_sendmessagesout.SetCommPort(1);

    // open the port

    m_sendmessagesout.SetPortOpen(TRUE);

    // squirt data out of port

    m_sendmessagesout.SetOutput(var);


    // close port again

    m_sendmessagesout.SetPortOpen(FALSE);

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