Solved

how to call DLL from VB

Posted on 2000-05-01
9
309 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
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!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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