Solved

how to call DLL from VB

Posted on 2000-05-01
9
312 Views
Last Modified: 2010-05-02
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 ?
0
Comment
Question by:alicia99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 3

Expert Comment

by:DrMaltz
ID: 2768162
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
 

Author Comment

by:alicia99
ID: 2768552
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2768625
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:syedAliF
ID: 2768750
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
 

Accepted Solution

by:
pushpak earned 45 total points
ID: 2768836
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2768870
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
 

Author Comment

by:alicia99
ID: 2771637
How do I give syedAliF and angelIII points at the same time?
0
 

Author Comment

by:alicia99
ID: 2771731
Adjusted points from 35 to 45
0
 

Author Comment

by:alicia99
ID: 2771732
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question