DLL Demo 1 - Empty DLL Project

What is a DLL? Many Windows applications, and Windows itself, are built built as a collection of callable DLLs (Dynamically Linked Libraries) rather than static executable binaries. For examples of this, check out the size of MS-Internet Explorer (IEXPLORE.EXE) which is only 89K, or the size of MS-Outlook Express (MSIMN.EXE) which is only 56K, yet both programs call the same "HTML rendering engine" which is implemented in the system DLLs. When you've got Outlook Express running at the same time as three instances of IE, there is only one set of DLLs loaded which definitely saves memory.

Notes:

  1. While IE is based upon hundreds of DLLs, other browsers like Firefox are static binary apps. This is why you can have multiple versions of Firefox on your system but only one version of IE
  2. Programmers coming from the mini-computer may be more familiar with the term RTL (Run Time Library)
  3. I've provided two methods of building the DLL but only one method of building the application. Since the DLL build is the hard part, you should have no difficulty with the application build.

"DllDemoEmpty1.dll" build using Visual-C++ (version 6)

click file->new->projects->"Win32 Dynamic-Link Library"
enter "DllDemoEmpty1" in the project name text box
click ok
select an empty DLL project
click finish
click file->new->files->"c++ source file"
enter "DllDemoEmpty1.cpp" in the file name text box
click ok
paste the contents of DllDemoEmpty1.h (below) into this window
click file->new->files->"c/c++ header file"
enter "DllDemoEmpty1.h" in the file name text box
click ok
paste the contents of DllDemoEmpty1.cpp (below) into this window
press key "F7" to build

"DllDemoEmpty1.dll" build using Visual-C++ (version 7.1 a.k.a. ".NET 2003")

click file menu->new->project
click Visual C++ Projects (in left hand pane)
click Empty Project .net (in right hand pane)
enter "DllDemoEmpty1" in the project name text box
click ok
click view menu->solution explorer (only if solution explorer is not visible in the left hand pane)
right click on "DllDemoEmpty1" then click on "properties"
double click on configuration properties
click on general
click on configuration type
select "Dynamic Library (.dll)" from the drop down menu
click on "Use Managed Extensions"
select "No" from the drop down menu (we do not want to invoke the common language runtime)
click "use of MFC"
select "use standard Windows Libraries" from the drop down menu
click "use of ATL"
select "not using ATL" from the drop down menu
click ok
right click on the "header files" folder
click "add->add new item" or "add->add existing item" to add file "DllDemoEmpty1.h"
right click on the "source files" folder
click "add-add new item" or "add->add existing item" to add file "DllDemoEmpty1.cpp"
right click on the "DllDemoEmpty" project folder
click on "rebuild"
//============================================================
// title  : DllDemoEmpty1.h
// purpose: required for DllDemoEmpty1.DLL
// author : Neil Rieck
// notes  : http://www3.sympatico.ca/n.rieck
//============================================================
#ifndef __DllDemoEmpty1_H				//
#define __DllDemoEmpty1_H				//
#ifndef __DllDemoEmpty1__				// define when calling from DLL
#define __DllDemoEmpty1LIB__ __declspec(dllimport)	// used when called from app
#else							//
#define __DllDemoEmpty1LIB__ __declspec(dllexport)	// used when called from demo
#endif							// ifndef else __DllDemoEmpty1__
//
// <<< prototype(s)
//
// these functions will be tagged for either import or export
//
__DllDemoEmpty1LIB__ unsigned long SimpleDouble( unsigned long whatever);
__DllDemoEmpty1LIB__ unsigned long SimpleTriple( unsigned long whatever);
#endif							// ifndef __DllDemoEmpty1_H

//============================================================
// title  : DllDemoEmpty1.cpp
// purpose: this program builds into DllDemoEmpty1.DLL
// author : Neil Rieck
// notes  : http://www3.sympatico.ca/n.rieck
//============================================================
#define __DllDemoEmpty1__	// force export mode
#include "DllDemoEmpty1.h"	// get exported prototypes
//
// note: this program doesn't have a function called DllMain()
//
//------------------------------------------------------------
// this function doubles whatever it receives
// (it has been marked for export in "DllDemoEmpty1.h")
//------------------------------------------------------------
unsigned long SimpleDouble( unsigned long whatever)
{	return (2 * whatever);
}
//------------------------------------------------------------
// this function triples whatever it receives
// (it has been marked for export in "DllDemoEmpty1.h")
//------------------------------------------------------------
unsigned long SimpleTriple( unsigned long whatever)
{	return (3 * whatever);
}

"DllDemoEmpty1Test.exe" build using Visual-C++ (version 6)

click file->new->projects->"Console Application"
enter "DllDemoEmpty1Test" in the project name text box
click ok
select a "Hello World" project
click finish
edit "DllDemoEmpty1Test.cpp" replace that code with the code below
copy files "DllDemoEmpty1.h", "DllDemoEmpty1.lib", "DllDemoEmpty1.dll" to this directory
click project->settings->link then add DllDemoEmpty1.lib to the end of the "Object/Library Modules" text box
(just click inside the box then press the "end" key)
press key "F7" to build
//============================================================
// title  : DllDemoEmpty1Test.cpp
// purpose: tests DllDemoEmpty1.DLL
// author : Neil Rieck
// notes  : http://www3.sympatico.ca/n.rieck
//============================================================
#include <iostream>
#include "DllDemoEmpty1.h" // get our function definitions

using std::cout;
using std::endl;

void main()
{   cout << "DllDemoEmpty1Test" << endl;
    cout << "=================" << endl;
    cout << "2*20=" << SimpleDouble(20) << endl;
    cout << "3*30=" << SimpleTriple(30) << endl;
}

Back to code stubs
Back to Home
Neil Rieck
Kitchener - Waterloo - Cambridge, Ontario, Canada.