Forum Discussion

Andreas_1's avatar
14 years ago

Call C DLL from js

Im trying ta access a routine in a C DLL but cant get the call right.



The code ive tried this far is like this:



function testsDLLCall()

{

    var Def_Enviroment, Def_DLL, pointerdatareply;

    var LpStr, Lib;


    Def_Enviroment = DLL.DefineEnvironmentByDLL("ddwrapper.dll");

    Def_DLL = Def_Enviroment.DefineDLL("ddwrapper.dll");

   

    Def_DLL.DefineProc("getDataInt", VT_LPSTR ,VT_BYREF | VT_PTR);

   

    LpStr = Def_Enviroment.New("LPSTR", 256);

   

    LpStr.Text = "Signalname";

   

    Lib = Def_Enviroment.Load("C:/TestCompleteMain/MainProject/ddwrapper.dll");


    Lib.getDataInt(LpStr, pointerdatareply);

}



The routine in the .h file:


//


// Routine to get int signal from DD


// signalName: Name of signal on DD (or dd_alias-name)


// result: 0 if value exist, -1 if not initialized on DD


// returns value of DD signal


//


DD_WRAPPER_API int getDataInt(char* signalName, int* result);


The error i get in TestComplete is 'Wrong number of arguments or invalid property assignment'.



Can anyone help me with the declaration and function call?

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 1 rankChampion Level 1
    Hi Victor,



    > DD_WRAPPER_API int getDataInt(char* signalName, int* result);

    Two notes:

    a) According to TC documentation, functions must use stdcall calling convention so TC can call them; and

    b) AFAIK, JScript does not support pointers and thus cannot call functions that have such parameters.



    P.S. I hope that Support will correct me if/where needed.
  • Victor,


    As far as I can see, the function declaration in the script code does not match the C function declaration.

    Your C function uses two parameters: char * and int *, and returns an int value --


    DD_WRAPPER_API int getDataInt(char* signalName, int* result);


    Your script code is --




    Def_DLL.DefineProc("getDataInt", VT_LPSTR ,VT_BYREF | VT_PTR);


    I suggest changing this script line in the following way --




    Def_DLL.DefineProc("getDataInt", vt_lpstr, vt_byref | vt_int, vt_int);


    Also, as Alexei wrote, DLL functions must use the stdcall convention. I don't know if DD_WRAPPER_API in your code corresponds to stdcall, but in order for you to be able to call this function, it should correspond to it.