LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing strings to a LAbVIEW application from Visual-C++ using ActiveX

Hello all,

I have built a LabVIEW application with ActiveX server enabled. I can start the application, and can read and set simple control values like
numerics.
But now I want to pass (SetControlValue) strings and read (GetControlValue) strings from controls.
After searching a whole day for examples or HowTos I found nothing. Can anyone give me tip where I can find something about that?
Examples are also appreciated.

Best regards
Heinrich Eidloth
0 Kudos
Message 1 of 5
(2,756 Views)
Both setting and getting values are done via ActiveX variant types. Thus you should be able to just read and write using BStrs or normal strings in VB. Speaking of which, what language is the client written in?
0 Kudos
Message 2 of 5
(2,751 Views)
Hello and Good Morning,

and thanks for the quick answer.

The client is written in C/C++ using Visual-C++ 6.0 (it is a small commandline executable for testing).

I have done the following:

......
VARIANT sText;
.....
sText = pVI->GetControlValue("message");
printf("Value: %s\n", sText.bstrVal);
.....

This will show me only the first character in my string to read (the complete string should be "Hello World :o)", what else).
I found out, that I have to use special functions for working with BSTR. I expanded my little application with the following
line, and I can see the correct length of my test string received.
.....
printf("Length: %i\n", SysStringLen(sTextbstrVal));
.....

So my question is, who do I get the  complete  string ? And what do I have to do, to set my control "message"?

I am not very familiar with C/C++, so if you could provide an example (or a link to an example) with some descriptions
woulb be really great.

Thanks in advance
Heinrich Eidloth


0 Kudos
Message 3 of 5
(2,745 Views)
The problem you are running into is that a BSTR is not a normal string (%s in the printf), but a wide character string (i.e., two bytes per character) string with the size stored in it. If the string contains ASCII characters, such as Hello World, then the one of the bytes per character is 0 (for example, 'H' would be 0x48 0x0).
 
When printf sees this, it thinks that it is a normal, null terminated string of "H". That is what you are seeing. You might try the %S (capital S) since that tells it the string is a wide character string.
 
Also note that BSTR's are part of the COM (Automation) system and so are don't freed with a delete or free() statement. Instead you need to release the memory with a SysFreeString() call.
 
If you aren't very familiar with C/C++, then you've taken on an advanced topic on top of a complicated language. If you can, you might want to try using either VB6 or .NET (C# or VB.NET). Those languages handle all of this for you automatically and you don't have to worry about freeing the memory.
 
If not, the book I started with to learn COM programming was this one (http://www.amazon.com/gp/product/1572313498/104-3574382-6511132?v=glance&n=283155&n=507846&s=books&v...).
 
0 Kudos
Message 4 of 5
(2,736 Views)
Hello again,

thanks for your tips.

I think your suggestions are a very good idea (especially for me).
I had played around with those strings in C/C++, and I found they are not very easy to handle.

Regards
Heinrich Eidloth

0 Kudos
Message 5 of 5
(2,725 Views)