?
Solved

Building DLL in VC++

Posted on 2005-03-16
9
Medium Priority
?
264 Views
Last Modified: 2010-04-01
How can I make DLLs in VC++ to use them in VB?
0
Comment
Question by:krisrajz
[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 8

Expert Comment

by:novitiate
ID: 13562433
Its easy

File->New->Projects:: Win32 Dynamiclink Library->Enter Name & Ok->A Dll that exports some symbols->Finish

Your dll is ready.

Now you can remove the class from that and add
extern "C" before all exported functions

You are there.

You may also considering createing COM Dll using ATL, using that will be straight forward.

_novi_
0
 
LVL 9

Accepted Solution

by:
rcarlan earned 1000 total points
ID: 13571529
As far as I know, VB doesn't support the __cdecl calling convention (I may be wrong). AFAIK, the default calling convention in VB is __stdcall.

__cdecl is the default calling convention in C/C++ and it requires the caller to reset the stack after the function returns.
__stdcall, on the other hand, guarantees that the called function will clear the stack before returning (i.e. caller doesn’t have to do anything after the function returns).

If you declare your exported functions like so:

extern "C" __declspec(dllexport) int DoSomething(int param1, int param2);

you will be exporting "DoSomething" with the __cdecl calling convention. You may have problems if you try to call this function from VB.

If you declare your exported functions like so:

extern "C" __declspec(dllexport) int __stdcall DoSomething(int param1, int param2);

you will be exporting "_DoSomething@8" with the __stdcall calling convention. You should be able to call the function successfully from VB (and any other programming language – e.g. Delphi), but the name is not very 'user-friendly'.

To have the best of both worlds, export the function as __stdcall and do the following in your DLL's .def file:

EXPORTS
          DoSomething

This will basically create a "DoSomething" alias for the "_DoSomething@8" __stdcall function you’re exporting.

0
 
LVL 1

Expert Comment

by:dumbo2569
ID: 13578247
Check out these websites. I had a similar project and these sites helped a lot.

http://www.flipcode.com/articles/article_vbdlls.shtml
http://www.zetnet.co.uk/rad/dll.html#onethree
0
Technology Partners: 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!

 
LVL 12

Expert Comment

by:topdog770
ID: 13672416
rcarlan, summed it up as succinctly as possible!


Here's a pretty good and detailed tutorial regarding VC++ DLL's and using them in VB
http://edais.mvps.org/Tutorials/CDLL/
0
 
LVL 9

Expert Comment

by:rcarlan
ID: 13735110
krisrajz,

How are you travelling on your DLL?

Radu
0
 
LVL 9

Expert Comment

by:rcarlan
ID: 13903345
I believe I've answered the question.

Another respondent, topdog770, acknowledged my answer and provided additional information in a form of a link to a website containing a tutorial on the topic.

Radu
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

771 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