NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

pass char array to c++ DLL and return same char array

Solved!
Go to solution

Lectori Salutem,

 

Here is the situation:

Im learning TestStand, and to learn the basics, I want to do the following:

Call a (C++) DLL in TestStand with an array of chars.

The DLL should return the array of chars (or a pointer to the datalocation).

 

This is the code in my DLL:

 

//////////////////////////////////////////////////////////////////////////////

 

 

TESTDLL3_API char* bounceString(char data[])
{
  data = "Hello World";
  cout << data;
char* pointer = data;
return pointer;
}
//////////////////////////////////////////////////////////////////////////////

However, this function will not be recognized by TestStand 😞

 

 

 

When this is working, I think I can build the rest of the functionality by myself.

 

Thanks in advance for any help!

 

Jeroen

The Netherlands

0 Kudos
Message 1 of 5
(9,293 Views)

Hi Jeroen,

 

Have you ever looked in TS-Example foulder: Examples\AccessingPropertiesUsingAPI\UsingMFC

In this Example there is a hole Visual Studio Project. Maybe you can use this for starting on scratch.

 

For passing strings back to TS, you should take a look on the CVI c-code Example in

Examples\Demo\C\Auto.c "Ignition_Test(xxx)"

 

Hope this helps

 

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 2 of 5
(9,274 Views)

Sadly, in the example there is no return value to TestStand.

However, I did manage to return the pointer of the char array to TestStand:

 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

 

int __declspec( dllexport )  bounceString2(char* argument)
{
  void *pointer;
  int i;
  argument = "Hello";
  pointer = argument;
  i = (int) pointer;
  return i;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
So, right now I have to find out how to retrieve the char array from the pointer...
Jeroen
PS, I will look at the CVI code, and let you know about my process

 

 

0 Kudos
Message 3 of 5
(9,272 Views)
Solution
Accepted by topic author Jeroen_Mechatronics

Fixed it 😄

 

It turns out, I had to declare a string variable in TestStand.

 

TestStand:

declare Locals.Text (string)

call the DLL module, with arg1 = char[1024] = Locals.Text

After calling the DLL, Locals.Text becomes Hello :D:D

 

 

Visual Studio DLL code:

 

void __declspec( dllexport )  bounceString2(char argument[])
{
  strcpy(argument, "Hello");
}

 

 

Anyone, thanks for the help!

 

Jeroen

Message 4 of 5
(9,264 Views)

Just to expand on this for anyone who finds this post later.

TestStand doesn't support functions that return char* because it can't deallocate the memory. So if you need a string back, it has to be passed as a parameter.

 

See this post by a TestStand devloper for more info:

http://forums.ni.com/t5/NI-TestStand/TestStand-pointeur-en-valeur-retourn%C3%A9e/m-p/904912/message-...

Josh W.
Certified TestStand Architect
Formerly blue
Message 5 of 5
(9,253 Views)