Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Building DLL in VC++

Posted on 2005-03-16
9
Medium Priority
?
268 Views
Last Modified: 2010-04-01
How can I make DLLs in VC++ to use them in VB?
0
Comment
Question by:krisrajz
6 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

580 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