Forum Discussion

PrathyushaCH's avatar
PrathyushaCH
Occasional Contributor
3 months ago

Calling functions from imported Dll in test complete

Hi,

Iam trying to access NavigateTo method from Core.dll for which iam using below code with c# scripting language in test complete. But iam unable to access above mentioned method with below code. Please help me with this.

function callDll(){
var IDefDLL = DLL["DefineDLL"]("Core");

var register = DLL["DefineType"]("NavigateTo", vt_string);

var Lib = DLL["Load"]("C:\\auto\\ExternalLibraries\\Core.dll", "Core"); 
  
}

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Does Core.dll belong to TestComplete or is this something you or someone else has developed?

  • PrathyushaCH's avatar
    PrathyushaCH
    Occasional Contributor

    It doesn't belong to Test Complete. Iam trying to import and access those functions

  • jennie258fitz's avatar
    jennie258fitz
    Occasional Contributor

    Hello, PrathyushaCH

    To call a method from an imported DLL in TestComplete using C#, you'll need to ensure that you correctly define and invoke the method. Here’s a structured approach to help you access the NavigateTo method from Core.dll.

    Step-by-Step Guide
    Define the DLL: Make sure you properly define the DLL and the function signature you intend to call.

    Load the DLL: Ensure you load the DLL correctly. Use the DLL.Load method to reference the DLL.

    Define the Function: You need to define the function you want to call from the DLL correctly. The parameters and return types must match the definitions in the DLL.

    Example Code
    Here’s an example that outlines how to do this:

    function callDll() {
        // Load the DLL
        var lib = DLL.Load("C:\\auto\\ExternalLibraries\\Core.dll");

        // Check if the DLL was loaded successfully
        if (lib == null) {
            Log.Error("Failed to load DLL");
            return;
        }

        // Define the NavigateTo method from the DLL
        var navigateTo = DLL.DefineFunction(lib, "NavigateTo", vt_string, [vt_string]); // Adjust parameter types as needed

        // Call the NavigateTo method
        var result = navigateTo("YourParameterHere"); // Replace with actual parameter

        // Log the result
        Log.Message("Result from NavigateTo: " + result);

        // Unload the DLL if necessary (optional)
        DLL.Unload(lib);
    }

    Key Points:
    DefineFunction: Make sure that the function signature matches what is defined in the DLL. The types (vt_string, etc.) need to be accurate.
    Parameter Types: Update the vt_string in the DefineFunction method with the correct parameter types according to the function definition in Core.dll.
    Error Handling: Always check if the DLL is loaded successfully and handle errors gracefully.
    Logging: Utilize logging to check if your calls are successful and to debug issues.

    Debugging Tips:
    Ensure that Core.dll is accessible at the specified path.
    Verify that the NavigateTo method exists in the DLL and that its signature matches what you're trying to define in TestComplete.
    Check the TestComplete documentation for any specific notes on using DLLs and calling external functions.
    Best regards,
    JennieF
    NYStateofHealth

  • PrathyushaCH's avatar
    PrathyushaCH
    Occasional Contributor

    " DLL.DefineFunction", This is not populating in Test complete. Is DefineFunction a valid function in Test complete?

    • rraghvani's avatar
      rraghvani
      Champion Level 3

      It's a new user, who has most likely used ChatGPT for an answer!