How to call dll from VB
Hi!! I was a beginner in dll.
My dll file was create in VC++, but how can I call those dll function from VB?
Thank You @!
You need to compile the dll with the __pascal calling convention, mark the relevant functions as exported, compile your dll, and then create a type library using the Microsoft IDL compiler (MIDL) to describe the functions. Once the type library is registered on a target machine, you should be able to put your dll in the system32 directory and make function calls into it from a VB program.
ld
ld
hi !! Nice to meet you... Thanks for your help..
I am not really understand about your explanation.. so sorry about that...
The dll file only have 1 function inside, which is :
From my VC++ program:
extern "C" int _declspec(dllexport) __stdcall Mymulti(int& a, int& b)
{
return a*b;
}
From my VB program:
Private Declare Function xxx Lib "dll.dll" Alias "_Myadd@8" (ByRef a As Long, ByRef b As Long) As Long
a = xxx(2, 3) --> X statement
It jam at X statement. I couldn't figure out what is going on.
You said that compile with __pascal, but how to do that?
How to mark the relevant function as exported?
How to create a type library?
How to register my dll on my machine?
Thank for your time @!
[edited by - huahsin68 on December 1, 2003 5:05:06 AM]
I am not really understand about your explanation.. so sorry about that...
The dll file only have 1 function inside, which is :
From my VC++ program:
extern "C" int _declspec(dllexport) __stdcall Mymulti(int& a, int& b)
{
return a*b;
}
From my VB program:
Private Declare Function xxx Lib "dll.dll" Alias "_Myadd@8" (ByRef a As Long, ByRef b As Long) As Long
a = xxx(2, 3) --> X statement
It jam at X statement. I couldn't figure out what is going on.
You said that compile with __pascal, but how to do that?
How to mark the relevant function as exported?
How to create a type library?
How to register my dll on my machine?
Thank for your time @!
[edited by - huahsin68 on December 1, 2003 5:05:06 AM]
__declspec(dllexport) marks your function as exported.
Compiling with __pascal is set in the compilation options on the Project Settings dialog, C/C++ tab. Select "Code Generation" in the dropdown (this is for VC++ 6.0, btw, it''s in the list somewhere in VC++.NET), and change the calling convention to __stdcall (the pascal calling convention renamed, basically).
Creating a type library is a process you will have to learn on your own. Here are the keywords: MIDL, IDL, ODL, "Interface Definition Language", "Object Definition language". There is enough on MSDN to get going, although I wouldn''t exactly call it good material. Registering the dll won''t be possible unless you link the type information directly into the dll, a process I have no experience with. Instead, create the type library and register it on your machine using regtlib.exe, then drop the dll into %WINDOWS%\system32.
ld
Compiling with __pascal is set in the compilation options on the Project Settings dialog, C/C++ tab. Select "Code Generation" in the dropdown (this is for VC++ 6.0, btw, it''s in the list somewhere in VC++.NET), and change the calling convention to __stdcall (the pascal calling convention renamed, basically).
Creating a type library is a process you will have to learn on your own. Here are the keywords: MIDL, IDL, ODL, "Interface Definition Language", "Object Definition language". There is enough on MSDN to get going, although I wouldn''t exactly call it good material. Registering the dll won''t be possible unless you link the type information directly into the dll, a process I have no experience with. Instead, create the type library and register it on your machine using regtlib.exe, then drop the dll into %WINDOWS%\system32.
ld
quote:Original post by huahsin68
From my VC++ program:
extern "C" int _declspec(dllexport) __stdcall Mymulti (int& a, int& b)
{
return a*b;
}
From my VB program:
Private Declare Function xxx Lib "dll.dll" Alias "_Myadd@8 " (ByRef a As Long, ByRef b As Long) As Long
5:05:06 AM]
This could be the problem, but then again you could be posting just as an example.
There''s (possibly) another problem here. The type int& is a reference to an int (this is a C++ thing, not a C thing) This could be confusing the compiler. Try using (since you are not changing the values a and b) int a, int b in the C function above, and change the Byref''s to ByVals ....
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement