Sei sulla pagina 1di 6

Blog

Active Sections
Welcome page
Programming
Computer Certifications
Computer Science
Open Source Projects
Mathematics for
Computer Science
Operating Systems
Parallel Computing
Computer Hardware
Databases
Networks
Data Mining
Book Reviews
Software Engineering
Pages
Recent changes
List all pages
Page Tags
Site Manager
Page tags
blog drupal_todo
needs_example qt
How to create and use DLL in
C++
Blog How to create and use DLL in C++
Posted on Friday: 06 May, 2011
The following steps apply for visual studio 2008.
Step 1: Create the project for the DLL.
Let's create a simple Win32 Console DLL: Visual
Studio > File > New Project > Win32 Console
Application
1.
Name it something sexy like MyDLL and press
OK.
2.
Press Next in the following screen and choose
DLL. Leave other options untouched.
3.
Press Finish. 4.
Step 2: Add the code for the DLL.
I will create a new class and add some simple code.
Right-click on Project name > Add > Class >
Name it something like Hel l oDLL
1.
Add the code that follows. 2.
To create the DLL export library: Project >
MyDLL properties > Configuration Properties
> C/C++ >Preprocessor > Append, or insert,
"DLLDIR_EX" (without the quotation marks) to
the Preprocessor Definition text box > OK. This
will prevent compiler assumptions and
warnings. [1]
3.
Build > Build Solution 4.
Your DLL should be ready. You should have files
MyDLL. dl l and MyDLL. l i b in directory pr oj ect -
di r ect or y\ Debug.
5.
HelloDLL.h
Download Free Software
mobogenie.com/download-software
Download Free PC Manager Software for Android. Download Now !
Programming Examples
Learn programming by doing examples.
contact Guest Post Policy
Search this site Search
Create account or Sign in
site-name .wikidot.com Share on

Edit History Tags Source Explore
How to create and use DLL in C++- Programming Examples http://programmingexamples.wikidot.com/blog:1
1 trong 6 30/12/2013 7:36 PM
todo-python todo_wordpress
Add a new page
new page
new Blog Entry
Share on Facebook
edit this panel
#pr agma once

/ / mor e about t hi s i n r ef er ence 1
#i f def DLLDI R_EX
#def i ne DLLDI R __decl spec( dl l expor t ) / / expor t DLL i nf o

#el se
#def i ne DLLDI R __decl spec( dl l i mpor t ) / / i mpor t DLL i nf o

#endi f

cl ass DLLDI R Hel l oDLL
{
publ i c:
Hel l oDLL( voi d) ;
~Hel l oDLL( voi d) ;

voi d hel l o( ) ;
st at i c voi d hel l oSt at i c( ) ;

};
HelloDLL.cpp
#i ncl ude " St dAf x. h"
#i ncl ude " Hel l oDLL. h"
#i ncl ude <i ost r eam>

usi ng namespace st d;

Hel l oDLL: : Hel l oDLL( voi d)
{
}

Hel l oDLL: : ~Hel l oDLL( voi d)
{
}

voi d Hel l oDLL: : hel l o( )
{
cout << " Hel l o Wor l d of DLL" << endl ;
}

voi d Hel l oDLL: : hel l oSt at i c( )
{
cout << " Hel l o Wor l d of DLL st at i c" << endl
}
Step 3: Use the DLL in a new project.
Create a new project: Visual Studio > File >
New Project > Win32 Console Application.
Name it Use of MyDLL and press OK.
1.
Press Next. 2.
Choose Console application. 3.
Press Finish. 4.
Step 4: Logistics for the new project.
Add file MyDLL. l i b in your project: Project >
Properties > Configuration Properties > Linker
> Input > Write the full path (including the
filename) in quotes. Example: "C:\Examples
\MyDLL\Debug\MyDLL.lib"
1.
.wikidot.com Share on

Edit History Tags Source Explore
How to create and use DLL in C++- Programming Examples http://programmingexamples.wikidot.com/blog:1
2 trong 6 30/12/2013 7:36 PM
Tweet 0
Fold
Fold
the source code of your project Use of MyDLL.
Add header file: Project > Properties >
Configuration Properties > C/C++ > Additional
Include Directories > Add the directory where
the file Hel l oDLL. h is located.
3.
Step 5: Test your DLL.
I used the following code:
#i ncl ude " st daf x. h"
#i ncl ude " Hel l oDLL. h"

i nt _t mai n( i nt ar gc, _TCHAR* ar gv[ ] )
{

Hel l oDLL hel l oDLL;
hel l oDLL. hel l o( ) ;
Hel l oDLL: : hel l oSt at i c( ) ;

get char ( ) ;

r et ur n 0;
}
Bibliography
1. Regular DLL Tutor For Beginners
2. C++ Tutorial: Create a DLL in VC++ 2010/2008
Rate this artile
rating: 0 + x
Bookmark this article
Leave a comment
Hide All Comments Unfold All Fold All
coder (guest) 4 Jun 2011, 01:58
Thanks for posting this valuable information and C++
source code! Very helpful. :-)
Reply Options
nattapon (guest) 14 Jan 2013, 14:09
+1
Reply Options
.wikidot.com Share on

Edit History Tags Source Explore
How to create and use DLL in C++- Programming Examples http://programmingexamples.wikidot.com/blog:1
3 trong 6 30/12/2013 7:36 PM
Fold
Fold
Fold
Fold
Fold
Fold
Fold
ChrysZ 8 Jun 2011, 13:32
Thanks coder.
Reply Options
Henry (guest) 14 Jun 2011, 14:41
May I know where is MyDLL.h file located?is it same
directory with MyDLL.cpp?I cant find it?
Reply Options
ChrysZ 14 Jun 2011, 14:47
There is no MyDLL.h or MyDLL.cpp. The only
source files are HelloDLL.h and HelloDLL.cpp.
MyDLL is the name of the project.
Reply Options
Henry (guest) 14 Jun 2011, 14:47
Hi,I manage to solve it oledi,the MyDLL.h of step
4,"Add header file: Project > Properties >
Configuration Properties > C/C++ > Additional
Include Directories > Add the directory where the file
MyDLL.h is located" should be is HelloDLL.h
Reply Options
ChrysZ 14 Jun 2011, 14:50
You are right. I changed it. Thanks Henry :)
Reply Options
Maverick (guest) 2 Sep 2012, 14:35
Hey, I have had to use dll file in some of my projects
in the past. My question is, say I only have a dll file,
no lib file or nothing else I only have dll and the
method listing using which I can use that dll from a
client program. Now, my question is, in situation
such as this, how could i include the lib directory, or
the header file ?
Another question would be, how to create standalone
dll file, so that i wont have to include header file, lib
file when i call the dll from the client program
Reply Options
justniik (guest) 19 Sep 2012, 01:00
realy nice tutorial
thanks
Reply Options
.wikidot.com Share on

Edit History Tags Source Explore
How to create and use DLL in C++- Programming Examples http://programmingexamples.wikidot.com/blog:1
4 trong 6 30/12/2013 7:36 PM
Fold
Fold
Fold
Fold
Darmaji (guest) 16 Oct 2012, 16:22
great tutorial..
it helps me to solve my problem..
thanks
:-)
Reply Options
about (guest) 21 Dec 2012, 07:04
I think you are using the static library instead,
because the dlls are load from code, for example in
Win32 it is necessary to use LoadLibrary().
Reply Options
shenba (guest) 25 Jan 2013, 14:15
Hi,
i have one utility and have to automatically install
the one dll to it. for that it need to ask about the
utility compatibility like version and it also ask for the
utility is pirate version or original version . if it is
original version it need to ask for the identity and
have to give the full access to it . otherwise some
properties of dll has to be hidden. then only it has
to install on utility. give me some ideas to do it.
pls
and this my mail id: mail2shenbagam@gmail.com

Reply Options
bharatmechanical1 (guest) 6 Mar 2013,
10:27
Hi, Can anybody help to suggest the steps for DLL
implementation.
I have prepared dll on WinXP(my development
machine) using MS Visula Studio 2010 and want to
test on WinNT(My UAT server).
When I try to register the DLL on UAT server for
usage..It says LoadLibrary(XXX.DLL) Failed. The
module not found.
Any idea what should I do to get my dll running and
picked by the application for testing.
Reply Options
or Sign in as Wikidot
user
(will not be published)
Name
E-mail address
.wikidot.com Share on

Edit History Tags Source Explore
How to create and use DLL in C++- Programming Examples http://programmingexamples.wikidot.com/blog:1
5 trong 6 30/12/2013 7:36 PM
- +
Help | Terms of Service | Privacy | Report a bug | Flag as objectionable
CUNEF Group C2
For Your Work, Opinions and
Discoveries!
Hilinqwo Math Aerobics
ADIDAS - All Day I Dream
About Sums..!!
NauticoAmager
Help: wiki text quick reference
Cancel Preview Post it
blog
page revision: 8, last edited: 14 Jun 2011, 14:49 (930 days
ago)
Edit Tags Discuss (13) History Files Print Site
tools + Options
Powered by Wikidot.com
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.
Other interesting sites
.wikidot.com Share on

Edit History Tags Source Explore
How to create and use DLL in C++- Programming Examples http://programmingexamples.wikidot.com/blog:1
6 trong 6 30/12/2013 7:36 PM

Potrebbero piacerti anche