05-11-2009 04:21 AM
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.
Solved! Go to Solution.
05-11-2009 06:24 AM
05-11-2009 10:27 AM
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.
05-12-2009 07:36 AM
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!