Forum Discussion

ahackmann's avatar
ahackmann
Occasional Contributor
14 years ago

Defining DLL Functions global

Hello,



I'm working with an selfmade DLL from Labview. I have defined some function in this DLL and everything is working fine. Now i have imported the DLL into my TestComplete function. (C#)



function test()

{

    Def_Environment = DLL["DefineEnvironment"](true); 

    Def_DLL = Def_Environment["DefineDLL"]("Labview");

 


    //Define DLL Function 

    Def_DLL["DefineProc"]("SetTestRackPower",VT_I1,VT_VOID);

    Def_DLL["DefineProc"]("SetPCOnOff",VT_I1,VT_VOID);



    //Load DLL

    Lib = Def_Environment["Load"]("C:\\Test Complete\\Autotest RSD 4.3\\Project\\Sources\\LabviewDLL\\SharedLib.DLL", "Labview");



    //Call function from DLL

    Lib["SetTestRackPower"](1);

    Lib["SetPCOnOff"](1);

}



Also in this TC function is everything working fine. I am able to call functions from the DLL. But is it possible to define the DLL, alternatively to define the functions from the DLL global so that i can call them from every function. I am calling many times functions and variables declared in another unit  but it seems to be that the functions from DLL must be defined in the function that use them? I want to define the DLL for example at the start of the test and then to call functions from the DLL in different Scripts and functions. Actually ervery time i call my "test" function I receive an Warning that the function is already defined.

I am working with Test Complete8 on a Windows XP SP3 machine.



Thanks a lot

Andreas

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Andreas,



    Try to declare the dll on test start and save reference to Lib variable in the Project Variable (of Object type) (e.g. Project.Variables.DLLvar = Lib;). Then use this project variable to call the function from the dll (e.g. Project.Variables.DLLvar["SomeFunction"](1);).



    Does it work?
  • ahackmann's avatar
    ahackmann
    Occasional Contributor
    Hi Alexei,



    thanks for your fast answer. I have tried your description but it does not work. Its the same problem as before.



  • Hi Andreas,





    It is quite odd that Alexei's suggestion does not work. Here is what I tried and this worked for me:







    //USEUNIT Unit2  





    function Main()

    {

      defineKernel32Lib();

      Unit2Test();

      Log.Message(Project.Variables.kernel32Lib.GetTickCount());

    }




    function Unit2Test()

    {

      Log.Message(Project.Variables.kernel32Lib.GetTickCount());

    }





    function defineKernel32Lib()

    {

      if (null == Project.Variables.kernel32Lib) {

        var Def_Environment = DLL.DefineEnvironment(true);

        var Def_DLL = Def_Environment.DefineDLL("kernel32");

        Def_DLL.DefineProc("GetTickCount", vt_i4);

        Project.Variables.kernel32Lib = Def_Environment.Load("kernel32");

      }

    }






    kernel32Lib is a temporary project variable of the Object type. The main idea is to declare all needed functions, load a library, put a library reference to a project variable and use this variable in any places where needed.
  • ahackmann's avatar
    ahackmann
    Occasional Contributor
    Hello David,



    thanks for your help. I tried your script and it works fine. My Mistake was that I didn"t define the DLL functions in the right way. So my problem is solved.



    Thanks for your benefits!