Solved

how to call DLL from VB

Posted on 2000-05-01
9
303 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
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 142

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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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 142

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now