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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VC++, MSComm.ocx & Null char's

Status
Not open for further replies.

yorklex

Programmer
Dec 27, 2001
3
US
Below is a snippet from the VCTerm example for VC++.
How can I get null characters into a variant and to transmit out the comm port using this control (example char* Test = "Te\0st\0Te\0st1";). I need to be able to do this for a special application interface to DDC controllers. It is really easy with VB but has proven next to impossible with VC++. Can anyone offer a helping hand and possibly an example?

CString ch(nChar);
VARIANT var;
char* Test = "Te\0st\0Te\0st1";



CCommCtrl* pCommCtrl = ((CMainFrame*)
AfxGetMainWnd ())->GetCommCtrl();
if (pCommCtrl->GetPortOpen())
{
var.vt = VT_BSTR;
var.bstrVal = ch.AllocSysString();
pCommCtrl->SetOutput(var);
VariantClear(&var);

Thanks,
Greg K.
York International Corp
 
What error are you getting? The first few lines of your code look troublesome:
[ignore]
CString ch(nChar);
VARIANT var;
char* Test = "Te\0st\0Te\0st1";

I think you intend to do this instead:

/* CString allocates the right amount of memory by itself */
CString ch = "Te\0st\0Te\0st1";
VARIANT var;

/* your program doesn't refer to Test, is it needed? */
char* Test = "Te\0st\0Te\0st1";

..
...
....
[/ignore]
So, first try correcting this... I haven't looked at the rest. If you still get an error, tell us what it is.

Hope this helps. ;-)
 
SysAllocString() will not copy complete strings with null char's embedded I'm guessing because it thinks all strings are null terminated. It was somewhat easier in standard C because you could use memcopy to copy the entire string into a char* and then point to the address of the string to send out to the comm port. There must be some way to do this that I am not thinking of since basic uses that same control and does not question null char's being thrown at it.

Greg K.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top