cancel
Showing results for 
Search instead for 
Did you mean: 

Call function of DLL at testcomplete

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 Smiley Surprisedbject doesn't support this property or method: 'Lib.add'

12 REPLIES 12
Contributor

Re: Call function of DLL at testcomplete

add attchment

Community Hero

Re: Call function of DLL at testcomplete

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
[Community Expert Group]
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
Extensions available
Community Hero

Re: Call function of DLL at testcomplete

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 Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Community Manager

Re: Call function of DLL at testcomplete

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

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Contributor

Re: Call function of DLL at testcomplete

hi  Community Manager

still no solution

 
Community Manager

Re: Call function of DLL at testcomplete

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

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Contributor

Re: Call function of DLL at testcomplete

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

Community Manager

Re: Call function of DLL at testcomplete


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 Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Contributor

Re: Call function of DLL at testcomplete

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

New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2
Top Kudoed Authors