Forum Discussion

ahackmann's avatar
ahackmann
Occasional Contributor
13 years ago

Get value from DLL function

Hello,

i am working with TC 8.70 and i am using JScript. Calling functions of a DLL is no problem but i get in trouble when i want to receive a value from DLL function. Any idea what is going wrong?

 

HEADER FILE OF DLL:

int16_t __stdcall Open(void);

int16_t __stdcall TPDI_POWER(uint16_t Function);

int16_t __stdcall TPDI_READ_Powerconsumptionvi(double *Voltage, double *Current);

 

SCRIPT:

 

Def_Environment = DLL.DefineEnvironment(true);

Def_DLL = Def_Environment.DefineDLL"TPDI_DLL");                                                  

                

Def_DLL.DefineProc("Open",VT_INT);

Def_DLL.DefineProc("TPDI_POWER",VT_I1,VT_INT);         

Def_DLL.DefineProc("TPDI_READ_Powerconsumptionvi",VT_BYREF | VT_R8 ,

VT_BYREF | VT_R8 ,VT_INT);

  

         

//Load into local directory

Project.Variables.DLLvar_Testrack = Def_Environment.Load("../TCAS_Tests/Sources/TPDI_DLL/TPDI_DLL.DLL","TPDI_DLL");

 

//open connection, working fine

Log.Message("Testrack open "+Project.Variables.DLLvar_Testrack.Open());  

 

//set Power to ON, working fine

Project.Variables.DLLvar_Testrack.TPDI_POWER(1);       

 

 

var voltage, current;  

       

// Get voltage and current from Power Supply is not working 

Project.Variables.DLLvar_Testrack.TPDI_READ_Powerconsumptionvi(voltage ,current);

 

Log.Message("Voltage:" +voltage + "     Current: " + current);  

 

 

 

I do not receive any error from TC but the values of “voltage” and “current” are undefined. Any ideas what i am making wrong?

 

Thanks in advance!

  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 3 rankChampion Level 3
    Hi Andreas,



    > [...] using JScript [...]

    > int16_t __stdcall TPDI_READ_Powerconsumptionvi(double *Voltage, double *Current);



    Considering that Open() and TPDI_POWER() functions are called fine, I think that the problem is with the (out) parameters passed by reference that cannot be processed by JScript.

    See http://support.smartbear.com/viewarticle/31116/ for more details and especially consider the last but one paragraph.

    As a possible workaround you may consider either to create a ScriptExtension (http://support.smartbear.com/viewarticle/28456/) and implement it using VBScript (that do not have problems with the parameters passed by reference) or create additional DLL that will wrap the call to TPDI_READ_Powerconsumptionvi() and return results in a way compatible with JScript.
  • ahackmann's avatar
    ahackmann
    Occasional Contributor
    Anyone with same / simlar problem? Is it at all possible to receive a value from DLL function with Test Complete? Any ideas?



    Thanks!