Forum Discussion

mailtosarojjena's avatar
mailtosarojjena
Occasional Contributor
15 years ago

calling dll

How can we call function present in win32dll which return string

4 Replies

  • swapnildaphal's avatar
    swapnildaphal
    Occasional Contributor
    Hello,

    I am accessing dll named "TestComplete_Related_Lib"  using 2 different ways ,second way is not working

    Dll contains 2 method coded in C#.net

    int ShowMsg(int,int)

    string Heloo()



    Here is the code inside dll

    namespace TestComplete_Related_Lib

    {

    public class Class1

    {

         public int ShowMsg(int num1,int num2)

        {

          int no1=num1;

          int no2=num2;

          return no1 + no2;

         }


         public string Heloo()

        {

           return "Hello";

         }


    }

    }








    Way 1 which works

    Calling Functions From .NET Assemblies  >>



    temp=dotNET.TestComplete_Related_Lib.Class1.zctor()

    var result=temp.ShowMsg(1,2); //returns correct addition as 3


    Log.Message(result)


    var result1=temp.Heloo().OleValue; //returns correct string as "Hello"


    *********************************************************************************

    Way 2 which doesn't work









    following is the code  :



    var Def_DLL, Def_DrawTextParams, Def_Rect,Def_Proc;


    Def_DLL = DLL.DefineDLL("TestComplete_Related_Lib");


    Def_Rect = DLL.DefineType("RECT",vt_i4, "num1", vt_i4, "num2")


    //Def_DLL.DefineAlias("ShowMsg", "ShowMsgA")


    Def_Proc = Def_DLL.DefineProc("ShowMsg",vt_i4);


    r = DLL.New("RECT");


    r.num1=4;


    r.num2=5;


    var path="C:\\Documents and Settings\\daphaswa\\My Documents\\Visual Studio 2008\\Projects\\TestComplete_Related_Lib\\TestComplete_Related_Lib\\bin\\Debug\\TestComplete_Related_Lib.dll"


    Lib= DLL.Load(path,"TestComplete_Related_Lib")


    //var n1=4,n2=5;


    //var temp= Lib.ShowMsg(n1,n2);


    var addition= Lib.ShowMsg(r.num1,r.num2);












    In debug mode object Lib  shows it has method ShowMsg but later on it gives error as <The function ShowMsg was not found in the TestComplete_Related_Lib.dll library.>



    Am I missing any statement?I have refered help topic "Calling Routines Located in Dynamic Link Libraries From Scripts"

    I am using TC6.5 enterprise edition.
























  • AlexKaras's avatar
    AlexKaras
    Community Hero
    Hi Swapnil,



    > I am accessing dll named "TestComplete_Related_Lib" [...] coded in C#



    This is the expected behaviour.



    From DLL Object help topic:

    "The DLL object supports only the routines that match the stdcall calling convention. (This calling convention is used by Windows API functions)."



    From Calling Functions From .NET Assemblies help topic:

    "With TestComplete you can call routines that reside in any .NET assembly from your scripts."



    So, you must use DLL object to call functions from non-.Net libraries and you must use dotNet object to work with .Net assemblies.