From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to pass array of char from test stand to DLL.

I waht to pass array of char like

char test[] = {0xFD,0x37,0x00};

to my dll function whose prototype is function(char* test_str);  the problem is that I cannot create a char array in teststand. How to do create one or any work around.

0 Kudos
Message 1 of 5
(5,616 Views)
Hi Vineet,

If you are calling a C/C++ DLL, the following section from the help should answer the question:

Edit C/C++ DLL Call Parameters

String Parameters

When using string parameters, use the C String Buffer or Unicode String Buffer type if you want the function to be able to change the contents of the argument in TestStand. Use the C String or Unicode String type if the DLL function does not modify the argument. You can pass a literal string, a TestStand string property, or an expression that evaluates to a string as the value of a string parameter.

The following settings are available in the Data Type ring control when you select String for the category type.

String Data Type Setting Equivalent C Data Type
C String const char *
C String Buffer char[]
Unicode String const wchar_t * or cont unsigned short *
Unicode String Buffer wchar_t[] or unsigned shortp[]

If you specify one of the string buffer types, the C/C++ DLL Adapter copies the contents of the string argument and a trailing zero element into a temporary buffer before calling the function. Specify the minimum size of the temporary buffer in the Buffer Size control. If the string value is longer than the buffer size you specify, the C/C++ DLL Adapter resizes the temporary buffer so that it is large enough to hold contents of the string argument and the trailing zero element. After the DLL function returns, TestStand copies the value that the function writes into the temporary buffer back to the string argument.

If you specify the C String or Unicode String type, the C/C++ DLL Adapter passes the address of the actual string directly to the function without copying it to a buffer. The code module must not change the contents of the string.

Note  You can pass NULL to a String pointer parameter by passing an empty object reference or the constant Nothing. Do not pass the constant 0.

Also, the following thread from the discussion forums may help:

passing a char *varname from test stand to a DLL
Cheers,

David Goldberg
National Instruments
Software R&D
Message 2 of 5
(5,598 Views)

Yes, you could pass a string. You can even encode byte values in the string with escape codes.

Another option, which might be mandatory if your byte array contains embedded zeros, is to define a numeric array where each element is a value that fits in a byte (0 to 255). Then pass the array as an array of bytes (numeric array of signed or unsigned 8 bit integers).

For the array argument, I think you could even pass an array literal such as {1,2,3,4} or {0x1, 0x2, 0x3, 0x4}.  For the dimension size, I think you can pass -1 to mean "the number of elements in the array argument I passed".

- James

 

0 Kudos
Message 3 of 5
(5,592 Views)
Hi ,AEDavid
//When using string parameters, use the C String Buffer or Unicode String Buffer type if you want the function to be able to change the contents of the argument in TestStand.
//Use the C String or Unicode String type if the DLL function does not modify the argument. You can pass a literal string, a TestStand string property, or an expression that
//evaluates to a string as the value of a string parameter.
 
I have doubt on this point.
const char* is a pointer to a const string, this means we should init the char* = "Hello", the pointer is must be point to a const. If we pass a const char* to the dll, the dll should be use this pointer to point to some const string, so we can get the change in this pointer. I guess you mean "content of the argument" is what the pointer's target, but I think in the dll we can pass any const string to this pointer such as "Hello","Hi" and so on.
 
I am not so sure of the TestStand datatypes, these days I am doing a project has a dll prototype with a const char* argument, I use it to come out some information from the dll to
TestStand to monitor the dll status, I do not know the if way is right.
********************************
*The best Chinese farmer*
********************************
0 Kudos
Message 4 of 5
(5,293 Views)

Hi paulbin,

Have you tested it out?  If so what issues are you seeing?

Regards,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 5 of 5
(5,274 Views)