NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

parse a returned object to string

Hello,

 

I'm calling a function exported by a C++ dll which returnes a pointer of char. In my call in teststand, a variable of Object Reference is used to get the returned pointer.

I now need to parse this object to a string or an array of string but don't find any info on how to do it.

 

Your help would be greatly appreciated.

 

Thanks,

 

Dave

0 Kudos
Message 1 of 5
(4,024 Views)
0 Kudos
Message 2 of 5
(4,013 Views)

@daveinca wrote:

Hello,

 

I'm calling a function exported by a C++ dll which returnes a pointer of char. In my call in teststand, a variable of Object Reference is used to get the returned pointer.

I now need to parse this object to a string or an array of string but don't find any info on how to do it.

 

Your help would be greatly appreciated.

 

Thanks,

 

Dave


Returning a char* from a C function is a bit tricky when mixing programming languages since who allocated and who should free the underlying memory for the string is not well defined. The easiest thing for you to do would be to write a utility function in a C/C++ dll that teststand can call that takes this pointer and fills in a string buffer also passed in by TestStand.

 

-Doug

0 Kudos
Message 3 of 5
(4,003 Views)

Hi Sathish, Doug,

 

Thanks for your reply.

Unfortunately, we can't add any extra code/module because of our strict policy here which is why I've been looking for a way in teststand only.

 

Dave

0 Kudos
Message 4 of 5
(3,996 Views)

This is a bit of hack, but you could configure a TestStand C/C++ Adapter step to call MultiByteToWideChar in the system Kernel32.dll. And for the source string you can pass your pointer type and for the wide character destination string set the parameter type to Unicode String Buffer.

 

This should work and get around your "no extra code modules" restriction since kernel32.dll is an OS dll that will exist on every machine.

 

-Doug

0 Kudos
Message 5 of 5
(3,993 Views)