how to call DLL from VB

How do I call a DLL from VB. After calling the DLL, how do I make use of it? Please explain in details! Besides, the DLL is exported from my class by using this:
class __declspec(dllexport) abc
{ ..... }
Since i export the whole class, how do I use one of the member function in VB6 ?
alicia99Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
pushpakConnect With a Mentor Commented:
Dear Alicia99
Hi! I think the dll u want to use , u should register them first and then reference it through project menu->references and then Choose the name of the dll u have just now registered. Now all the class ,Properties, Member Function and events will be available to u. U can use them  by making a variable of the class u have defined in to the Dll u can call the function u have defined into dll.
0
 
DrMaltzCommented:
VB has some stringent rules/requirements that must be followed.  For starters, vb expects the dll to work like functions being called from Win32 API..

You have to make sure the function maintain the stack.  This is in done when developing your dll.  You must  apply the _stdcall keyword.  

So, you've one part right.. you do need the __declspec(dllexport), but you need the _stdcall.  Here's an example..

_delcspec(dllexport) long _stdcall DebugPrint (LPSTR szMessage)

I hope this information is helpful..
0
 
alicia99Author Commented:
My question is not answered ! Why? I wish to know how am I going to call DLL from VB if only one of the member function in that class(Visual C++ 6) which I exported i wanna use only.

Is there any method that I can shortened the function name that i exported? I use "Depends" to view the DLL file that I've exported. I saw something like this:-
??0CATMException@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z

The original function name is "CATMEexception"

Is it valid for me to export one of the member function in C++ while the function is inside a class or should the whole class be exported?

Thank you.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I think you need to register you dll (which seems to be ActiveX dll)
Then you can check in the references dialog box of the VB project and use the objectbrowser to analyse your class.

You are correct when you say that you need to export the whole class, normally, exporting a single function cannot be of use (except if the function is a completely standalone)
0
 
syedAliFCommented:
The mangled thing that you are seeing is due to not exporting the function properly from VC++
??0CATMException@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
This kind of exports are not acceptable by VB.The dll has to be compiled with .DEF file which has the Exports Table.If you compile this way you will not get those characters.
To call this function in VB
you have to declare it as API call in a module e.g
Public Declare Function Square Lib "vblibrary.dll" (ByVal itest As integer) As Long

Private sub Command1_click()
dim x as long
x=Square(5)
end sub
Hope this will help you...




0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Dear pushpak:
Please revert you answer to a comment, because this text is already given.
FYI: comments can be accepted as an answer too
0
 
alicia99Author Commented:
How do I give syedAliF and angelIII points at the same time?
0
 
alicia99Author Commented:
Adjusted points from 35 to 45
0
 
alicia99Author Commented:
Helo Pushpak,

If i have included the DLL in my reference, do i still need to declare this:-
Declare Function hello Lib "vblibrary.dll" (ByVal itest As String) As String

As for syedAliF,
If i have the whole c++ class exported as a DLL, then it is a class, not a function! So how do I declare it?
I wish to use one or two function that belong to the C++ class only. How do i declare it using VB?

Please help. Thank you.
 
0
All Courses

From novice to tech pro — start learning today.