Forum Discussion

venkat001's avatar
venkat001
Occasional Contributor
13 years ago

Calling dll from TestComplete script

Hi,



I'm writing a TestComplete script to pass arguments (int) to AQ_SetStart function in dll (dll is wrriten inV C++).  Below is my C++ code for dll  functions. While executing this TestComplete script,  getting below error . And appreciate your early help.



Error

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

An exception occurred in the "Unit1" unit at line 38:
Microsoft VBScript runtime error
Object doesn't support this property or method: 'Lib.AQ_SetStart'An exception occurred in the "Unit1" unit at line 38:

Microsoft VBScript
runtime error

Object doesn't support this property or method:
'Lib.AQ_SetStart'

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



Below code is used in dll



#include<windows.h>

#include"justDLL.h"



void AQ_SetStart(int a)

{

    temp =a;

}



int AQ_GetStart()

{

    return temp;

}

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

Below is JustDLL.h code



int temp;

extern"C"

__declspec(dllexport)

void AQ_SetStart(int);



extern"C"

__declspec(dllexport)

int AQ_GetStart();

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

Below is TestComplete VBscript to call this dll and pass int values



Sub TestFunction

  Dim MyStructID, A1, Def_DLL, Lib



  MyStructID = DLL.DefineType("Mystruct", _

                            vt_i4, "First")

  Set A1 = DLL.New("Mystruct")



  A1.First = 1

 

  Set Def_DLL = DLL.DefineDLL("DD1440A_DAQ_V_1.dll")

  Set Lib = DLL.Load("C:\Users\20039895\Desktop\Test Complete_Tututorial\Custom_DLL\DD1440A_DAQ_V_1.dll")

  call Def_DLL.DefineProc ("AQ_SetStart", VT_INT)

   

  Lib.AQ_SetStart A1  

    

End Sub
  • Hi,



    Your DefineProc call is incorrect. You must specify the return type after parameter types. The return type in your case is vt_void.



    Also, passing a custom structure to a function which accepts int as its parameter probably won't work. Pass an integer value instead of a structure to your function.
  • venkat001's avatar
    venkat001
    Occasional Contributor
    Thanks for your response. I tried still its not working. If i call same dll in LabVIEW i can see the functions written in this dll but not in Testcomplete.



    Regards,

    Venkateswaran K
  • Hi,



    So what is your current code and what exact error do you get?
  • venkat001's avatar
    venkat001
    Occasional Contributor
    Hi,



    Sub TestFunction

      Dim  A, Def_DLL, Lib

      A=1

     

      Set Def_DLL = DLL.DefineDLL("DD1440A_DAQ_V_1.dll")

      Set Lib = DLL.Load("C:\Users\20039895\Desktop\Test Complete_Tututorial\Custom_DLL\DD1440A_DAQ_V_1.dll")

      call Def_DLL.DefineProc ("AQ_SetStart", vt_void, vt_int)

       

      Lib.AQ_SetStart A 

        

    End Sub



    Error



    An exception occurred in the "Unit1" unit at line 38:
    Microsoft VBScript runtime error
    Object doesn't support this property or method: 'Lib.AQ_SetStart'An exception occurred in the "Unit1" unit at line 38:

    Microsoft VBScript
    runtime error

    Object doesn't support this property or method:
    'Lib.AQ_SetStart'





    Regards,

    Venkateswaran K
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi
    Venkateswaran,



    I would recommend you to carefully go through help topics that describe calling DLL functions from TestComplete scripts and follow their recommendations/samples (http://support.smartbear.com/viewarticle/11430/ and related) as on the first glance the DefineProc call in your code is still incorrect - AFAIR, the function's return type must be the last parameter, while in your code it seems to be in the middle.
  • Hi,



    Alexei is right, your DefineProc is incorrect. Function parameters are defined left to right, and the return type is defined last.
  • venkat001's avatar
    venkat001
    Occasional Contributor
    Hi Alexei & Jared,



    Can you please define the code how should i write instead of saying code is incorrect. I have tried all possibilities which is listed below.



    call Def_DLL.DefineProc ("AQ_SetStart", vt_void , vt_int)



    call Def_DLL.DefineProc ("AQ_SetStart", VT_INT)



    call Def_DLL.DefineProc ("AQ_SetStart", vt_void)



    call Def_DLL.DefineProc ("AQ_SetStart", vt_int , vt_void)



    Appreciate your help.





    Regards,

    Venkateswaran K
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi
    Venkateswaran,



    According to your description, the fourth version should be correct (call Def_DLL.DefineProc ("AQ_SetStart", vt_int , vt_void)).

    If it does not work, I would recommend to either post here or submit a Support Request (http://support.smartbear.com/support/message/) and provide the full contents of script and library function code (C-source and header file). My guess is that some mandatory declaration (like stdcall) was missed when creating the dll library.
  • venkat001's avatar
    venkat001
    Occasional Contributor

     Thanks Alexei, still same error as mentioned above. attached the .dll function code and TestComplete code for your reference. I would recomend you to post  working code here.



    Appreciate your help.


    Best Regards,

    Venkates K