Archived

This topic is now archived and is closed to further replies.

How to call dll from VB

This topic is 5128 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
__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

Share this post


Link to post
Share on other sites
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 ....



Share this post


Link to post
Share on other sites
Hi Guys!!

My VB program keep on showing error message said that: file not found .. I have put my file in my working project directory. I think I have make the right DLL file. Before this it also showing this error message.

Where should I put my dll file?

Thank You @!

Share this post


Link to post
Share on other sites