ASCII string in dataOut struct of COM function

26 views
Skip to first unread message

Wolfgang

unread,
Nov 25, 2009, 2:52:00 PM11/25/09
to IADS
Hi everybody!
We use derived parameters with our own COM functions to get IADS
running
with more than 1 update per second. These Functions deliver a value of
type
double. Example:

STDMETHODIMP MyFunction::Compute( /*[in]*/ VARIANT* dataIn, /*[out]*/
VARIANT* dataOut )
{
...
dataOut->vt = VT_R8; // Result is a double
dataOut->dblVal = (double)(p1 + p2 + p3); // Result

return S_OK;
}

This works.

Now we want to create a text string. How? And which Display Object
will display the String?
This one doesen´t work:

STDMETHODIMP MyFunction::Compute( /*[in]*/ VARIANT* dataIn, /*[out]*/
VARIANT* dataOut )
{
...
static char str[] = {"SF237"}; // Example string
dataOut->vt = VT_BSTR; // Result is a string
dataOut->??? = ???; // Result

return S_OK;
}

Hopefully someone knows how to do it. We have to display many of this
this strings. Every String consists of 5 independent charcters, driven
by telemetry data values. If we must use the TEXT Object with a
propert bag for every single character it will not only be more work
to create and maintain the derived parameters and the displays, but it
will slow down the update rate.

-----------------------------------------------------------
--- Wolfgang, SYS500 Model550, IADS 6.1 ---

James Bretz

unread,
Nov 25, 2009, 3:20:33 PM11/25/09
to ia...@googlegroups.com
Hi Wolfgang,

> We use derived parameters with our own COM functions to get IADS
> running with more than 1 update per second. These Functions deliver a
> value of
> type double.

Sounds like you are having performance issues. Are you having a hard time
getting the displays to update more than 1 time per second for some reason?
If so, this is very unusual... in fact, I've seen over 15k parameters on the
same desktop running over 10 updates per second. Let me know if that's the
case and we can analyze the issue.

> Now we want to create a text string. How? And which Display Object
> will display the String?
> This one doesen�t work:
>
> STDMETHODIMP MyFunction::Compute( /*[in]*/ VARIANT* dataIn, /*[out]*/
> VARIANT* dataOut )
> {
> ...
> static char str[] = {"SF237"}; // Example string
> dataOut->vt = VT_BSTR; // Result is a string
> dataOut->??? = ???; // Result
>
> return S_OK;
> }

Ok, you're really close ;)

Actually, you need to return a "BSTR" (wide character) string:

static char str[] = {"SF237"}; // Example string
dataOut->vt = VT_BSTR; // Result is a string
dataOut->bstrVal = ::SysAllocString( str ); //
Result

If you get stuck, there is an example of returning a string:

http://www.symvionics.com/products/IADS/Downloads/SampleFunctionVC.zip

Check out the SampleFunction2 class.


> Hopefully someone knows how to do it. We have to display many of this
> this strings. Every String consists of 5 independent charcters, driven
> by telemetry data values. If we must use the TEXT Object with a
> propert bag for every single character it will not only be more work
> to create and maintain the derived parameters and the displays, but it
> will slow down the update rate.

Hmmm... Yes, this will work fine, but it's hard to believe that this method
would be faster than the tableLookup in the Dynamics system. What type of
PC are you running on?

Don't let my comments stop you though. If it works better/faster than just
use it. I'd be curious to see the original AnalysisWindow so I can run some
performance testing,
Jim





>
> -----------------------------------------------------------
> --- Wolfgang, SYS500 Model550, IADS 6.1 ---
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "IADS" group.
> To post to this group, send email to ia...@googlegroups.com.
> To unsubscribe from this group, send email to
> iads+uns...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/iads?hl=en.
>
>

James Bretz

unread,
Nov 25, 2009, 11:08:44 PM11/25/09
to ia...@googlegroups.com
Wolfgang,

Actually, I think the code I wrote will leak memory:

> static char str[] = {"SF237"}; // Example string
> dataOut->vt = VT_BSTR; // Result is a string
> dataOut->bstrVal = ::SysAllocString( str ); // Result

We broke convention a little with returning strings to prevent the need to
reallocate a new string. The example above creates a new string for every
return value. This is cause the function to leak memory. At this point you
would want to allocate the BSTR string *once* and then copy the new string
value into it each time.

Also, I incorrectly setup the SysAllocString function above. It expects a
wide character string.

Probably the easiest way to handle the wide character strings is to use the
CComBSTR class, but if you're not used to with this class, it's a painful
learning curve because all the functions are different.

I think your best option is to download the example from the last post and
look at the SampleFunction2 class. Another issue is that I think this only
works with Iads version 6.2 and greater.

If you have any questions just let me know,
Jim


Wolfgang

unread,
Nov 26, 2009, 2:59:12 PM11/26/09
to IADS
Jim,

> > static char str[] = {"SF237"};              // Example string
> > dataOut->vt = VT_BSTR;                   // Result is a string
> > dataOut->bstrVal = ::SysAllocString( str );            // Result

works. But the resulting display is a very big number - no text.
Maybe because we use IADS 6.1.

I will start a new diskussion with the IADS performance problem.

James Bretz

unread,
Nov 26, 2009, 3:14:50 PM11/26/09
to ia...@googlegroups.com
Wolfgang,
Ganz richtig. Sie mussen IADS 6.2+ haben.

Maybe we can resolve the performance issue,
Jim

Wolfgang

unread,
Jan 18, 2010, 4:05:05 PM1/18/10
to IADS
Jim,

I installed IADS 6.3 and now it works!

// Example:
...
static OLECHAR str_out[20];
str_out[0] = 'A';
str_out[1] = 'B';
str_out[2] = '1';
str_out[3] = '2';
str_out[4] = '\0';
dataOut->vt = VT_BSTR;
dataOut->bstrVal = ::sysAllocString( str_out );
...
// end of example

The Annunciator, the activeX Text and the activeX TextInput can
display the Text.

But as you said, it is a memory leak.

I couldn't find a hint to prevent the memory leak in the
SampleFunctionVC.zip.

Somehow this Function should provide a separate amount of memory for
every derived parameter that is using the function but not for every
invocation of the function. I know exactly how to do this with a
Sys500 function, but how can it be done with IADS?
Any idea?

Wolfgang

Jim Bretz

unread,
Jan 18, 2010, 4:10:54 PM1/18/10
to ia...@googlegroups.com
Hi Wolfgang,

Try making the BstrVal a "member variable" of the class and only allocate it
once. Notice that the SampleFunctionVC allocates the string in the
constructor.

Jim

Reply all
Reply to author
Forward
0 new messages