NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand pointeur en valeur retournée

Solved!
Go to solution

Bonjour,

 

je dois utiliser une fonction dll standard, qui renvoie une chaine de caratctères : Prototype C : char  * version();

Vu qu'il n'y a pas de possibilité de récupérer un pointeur dans une valeur retournée, comment peut-on récupérer la texte dans un appel de fonction TestStand ?

 

Merci pour votre aide.

 

Jean-Marie.

JMCe
0 Kudos
Message 1 of 4
(3,870 Views)
(same question in english) : Hello,
 
I have to use a standard dll function , which returns a string pointer : (C prototype: char * version (void));

Given that there is no possibility inTestStand getting back a pointer in a returned value, how can we get back text in such a function call ?

 
Thank you for your help.

 
Jean-Marie.

JMCe
0 Kudos
Message 2 of 4
(3,865 Views)

TestStand does not currently support string return values because TestStand doesn't know how to deallocate the memory associated with the string. If you must call a function in a standard DLL that returns a string, you have a couple of options. Each of them requires you to write your own DLL.

 

1. Write a wrapper function in a DLL that calls the string function. Your wrapper DLL must link to the standard DLL. For example,

  
void VersionWrapper(char returnValue[], int bufferLength)
{
    char *versionString = version();
    if (versionString != NULL)
    {
        strncpy(returnValue, versionString, bufferLength);
    }
    // You must deallocate versionString here if necessary.
}

2. Call the string function in TestStand manually specifying the return value as an integer. Write a conversion function in a DLL that converts the integer to a char pointer. For example,

 

void ConvertIntToString(int returnValueFromTestStand, char returnValue[], int bufferLength)
{
    const char *returnValueString = (const char *)returnValueFromTestStand;
    if (returnValueString != NULL)
    {
        strncpy(returnValue, returnValueString , bufferLength);
    }
    // You must deallocate returnValueString here if necessary.
}

Note: If the string function in the standard DLL is exported with a C++ decorated name, the function will not appear in the function list in TestStand and you cannot use option 2.

Message 3 of 4
(3,846 Views)
Solution
Accepted by topic author J.M. Cereuil

Hi Erik,

 

thanks for yor reply. The second option was what i've tried yesterday, (as i don't have the source code for the version function).

here is my c code for a very little dll :

 

void __declspec(dllexport) GiveMeTheText(long pointeur, char *Texte)
{
    if (pointeur != 0)
        strcpy (Texte, (char *) pointeur);
}
as Pointeur is a TestStand value, it's equal to 0 or plus.

Texte is also a TestStand string, then not null.

It is a pity we do not find it in the TestStand AP.

 

Thanks a lot!

JMCe
0 Kudos
Message 4 of 4
(3,824 Views)