Forum Discussion

subbuV's avatar
subbuV
New Contributor
7 years ago
Solved

Calling DLL Objects from TestComplete

I am currently trying to call an object from a DLL but not sure how best to do it in TestComplete. There is a DLL that our development team has produced (CompassAPI.dll) which is a COM object. I would like to load this DLL and call objects/functions from this DLL.

 

I believe this is what I need:

https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calling-from-dll/tutorial.html

 

However, I am struggling to follow the tutorial - not sure if I need to do all the steps in the tutorial for my case.

 

Here is a quick test that I want to do (as described in the API guide):

 

'Create the API session
Set pCProphAPISession = New ProphAPISession

'Call the logon method to start an API session
Call ProphAPISession.Logon("User")

 

 

How can I load the DLL in TestComplete and start calling the objects as above? I am currently trying to write equivalent DelphiScript but in fact, any scripting language should be fine.

 

I also read about accessing COM objects in TestComplete but I have no idea about ProgID or CLSID:

https://support.smartbear.com/testcomplete/docs/scripting/working-with/com-objects.html

 

Any help or pointers to get me started would be much appreciated. Thanks.

  • Hi,

     

    > (CompassAPI.dll) which is a COM object.

    This means that this dll cannot be used via the DLL access in TestComplete because DLL functionality makes it possible to access regular functions exported by DLLs. (Read TestComplete documantation and talk to developers for more info on DLL exported functions.)

    As this is a COM object, you must work with it as with any other COM dll:

    -- COM object(s) provided by this dll must be registered in the system. Usually this is done via the 'regsvr32 <file.dll>' command, but if this dll is .Net-based, some other steps might be required. Talk to your developers and ask them how to do the registration in your system;

    -- After COM objects are registered, you can create their instances in your test code via the Sys.OleObject() method. E.g. Sys.OleObject('Excel.Application') will instantiate an instance of Excel COM object. You must know COM object identifier (ProgID) (Excel.Application in the previous example) to create an object instance. Ask your developers or your documentation if you don't know it.

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    > (CompassAPI.dll) which is a COM object.

    This means that this dll cannot be used via the DLL access in TestComplete because DLL functionality makes it possible to access regular functions exported by DLLs. (Read TestComplete documantation and talk to developers for more info on DLL exported functions.)

    As this is a COM object, you must work with it as with any other COM dll:

    -- COM object(s) provided by this dll must be registered in the system. Usually this is done via the 'regsvr32 <file.dll>' command, but if this dll is .Net-based, some other steps might be required. Talk to your developers and ask them how to do the registration in your system;

    -- After COM objects are registered, you can create their instances in your test code via the Sys.OleObject() method. E.g. Sys.OleObject('Excel.Application') will instantiate an instance of Excel COM object. You must know COM object identifier (ProgID) (Excel.Application in the previous example) to create an object instance. Ask your developers or your documentation if you don't know it.

    • subbuV's avatar
      subbuV
      New Contributor

      Hi Alex,

       

      Thanks, the COM object method that you suggested works. I am able to access objects and functions from the dll now.

       

      Regards,

      Subbu

      • fazlook's avatar
        fazlook
        Frequent Contributor
        Is it .Net dll ?

        Just go to your Project Properties -> Select CLR Bridge (under general) and then browse to your dll location.

        To use in TC:

        DotNET.CompassAPI.ProphAPISession.Logon("User").