Ask a Question

Call function of DLL at testcomplete

nikki85
Contributor

Call function of DLL at testcomplete

Hi Buddy ,

i failed to call function of DLL which is developed in C++

the function of DLL in C++ as below

#include "stdafx.h"
 int add(int a, int b)
{
  return a + b;

}

 

my script at testcomplete is as below

sub test
dim a
set Def_Dll=DLL.DefineDLL("test_dll")

Call Def_DLL.DefineProc("addA",vt_i4,vt_i4,vt_i4)
Call Def_DLL.DefineAlias("add", "addA")
                   
set Lib=Dll.Load("C:\Users\H208139\Desktop\test_dll\Debug\test_dll.dll","test_dll")

a=Lib.add(1,2)
log.Message(a)

end sub

 

test result :Object doesn't support this property or method: 'Lib.add'

12 REPLIES 12
nikki85
Contributor

add attchment

tristaanogre
Esteemed Contributor

I'm not 100% certain.... but you are defining the procedure/method and giving it an Alias of addA.  The DefineProc should be using the method name as it is called in the DLL....  So, with that, shouldn't your code be...

 

sub test 
dim a
set Def_Dll=DLL.DefineDLL("test_dll")

Call Def_DLL.DefineProc("add",vt_i4,vt_i4,vt_i4)
Call Def_DLL.DefineAlias("addA", "add")
                    
set Lib=Dll.Load("C:\Users\H208139\Desktop\test_dll\Debug\test_dll.dll","test_dll")

a=Lib.addA(1,2)
log.Message(a)

end sub

 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
AlexKaras
Champion Level 3

Hi,

 

Check that your DLL meets requirements from https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calli....

Especially those:

-- Only standalone exported routines can be called from TestComplete tests. There is no way to call methods of exported classes.

-- The DLL routine to be called must match the stdcall calling convention.

 

Also check the bitness of TestComplete and DLL (https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calli...).

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
TanyaYatskovska
SmartBear Alumni (Retired)

@nikki85, did you find an answer to your question? Please, share your solution with us.

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



hi  Community Manager

still no solution

 
TanyaYatskovska
SmartBear Alumni (Retired)

Have you tried suggestions given here? What exactly doesn't work when applying them?

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



yes , I  tried suggestions given here, error message is still object doesn't support this property or method: 'Lib.add'

TanyaYatskovska
SmartBear Alumni (Retired)


I don't see the stdcall calling convention in your original dll as Alex mentioned:

@AlexKaras wrote:

The DLL routine to be called must match the stdcall calling convention.


At the same time, this is one of the requirements.

 

I'm not familiar with C++ very well - I suppose you should declare the add routine something like this:

 int __stdcall add(int a, int b) 
{
	 return a + b;
}

If you modified the dll, it's worth posting the new one, as well as the updated code.

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



Hi TanyaGorbunova,

Thanks for your reply

I add the __stdcall at dll ,but the error message is the same : Object doesn't support this property or method: 'Lib.AddA'

My scripts in VBscript as below :
sub test
dim a
Set Def_Environment = DLL.DefineEnvironment(True)
Set Def_DLL = Def_Environment.DefineDLL("test_dll")
set Lib=Def_Environment.Load("C:\Users\H208139\Desktop\test_dll\Debug\test_dll.dll","test_dll")
Call Def_DLL.DefineProc("AddA",vt_int,vt_int,vt_int)
a=Lib.AddA(2,2)
log.Message(a)
end sub

 

And I attached the modified dll

cancel
Showing results for 
Search instead for 
Did you mean: