Notes:
| click | file->new->projects->"Win32 Dynamic-Link Library" | 
| enter | "DllDemoSimple2" in the project name text box | 
| click | ok | 
| select | an simple DLL project | 
| click | finish | 
| click | file->new->files->"c++ source file" | 
| enter | "DllDemoSimple2.cpp" in the file name text box | 
| click | ok | 
| paste | the contents of DllDemoSimple2.h (below) into this window | 
| click | file->new->files->"c/c++ header file" | 
| enter | "DllDemoSimple2.h" in the file name text box | 
| click | ok | 
| paste | the contents of DllDemoSimple2.cpp (below) into this window | 
| press | key "F7" to build | 
//============================================================ // title : DllDemoSimple2.h // purpose: required for DllDemoSimple2.DLL // author : Neil Rieck // notes : https://neilrieck.net //============================================================ #ifndef __DllDemoSimple2_H // #define __DllDemoSimple2_H // #ifndef __DllDemoSimple2__ // define when calling from DLL #define __DllDemoSimple2LIB__ __declspec(dllimport) // used when called from app #else // #define __DllDemoSimple2LIB__ __declspec(dllexport) // used when called from DLL #endif // ifndef else __DllDemoSimple2__ // // prototype(s) // // these functions will be tagged for either import or export // __DllDemoSimple2LIB__ unsigned long SimpleDouble( unsigned long whatever); __DllDemoSimple2LIB__ unsigned long SimpleTriple( unsigned long whatever); #endif // ifndef __DllDemoSimple2_H
//============================================================ // title : DllDemoSimple2.cpp // purpose: this program builds into DllDemoSimple2.DLL // author : Neil Rieck // notes : https://neilrieck.net //============================================================ #include "stdafx.h" // #define __DllDemoSimple2__ // force export mode #include "DllDemoSimple2.h" // get exported prototypes // // see MDSN info on how to expand DllMain() // BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { // Perform actions based on the reason for calling. switch( fdwReason ) { case DLL_PROCESS_ATTACH: // Initialize once for each new process. // Return FALSE to fail DLL load. break; case DLL_THREAD_ATTACH: // Do thread-specific initialization. break; case DLL_THREAD_DETACH: // Do thread-specific cleanup. break; case DLL_PROCESS_DETACH: // Perform any necessary cleanup. break; } return TRUE; // Successful DLL_PROCESS_ATTACH. } //------------------------------------------------------------ // this function doubles whatever it receives // (it has been marked for export in "DllDemoSimple2.h") //------------------------------------------------------------ unsigned long SimpleDouble( unsigned long whatever) { return (2 * whatever); } //------------------------------------------------------------ // this function triples whatever it receives // (it has been marked for export in "DllDemoSimple2.h") //------------------------------------------------------------ unsigned long SimpleTriple( unsigned long whatever) { return (3 * whatever); }
| click | file->new->projects->"Console Application" | 
| enter | "DllDemoSimple2Test" in the project name text box | 
| click | ok | 
| select | a "Hello World" project | 
| click | finish | 
| edit | "DllDemoSimple2Test.cpp" replace that code with the code below | 
| copy | files "DllDemoSimple2.h", "DllDemoSimple2.lib", "DllDemoSimple2.dll" to this directory | 
| click | project->settings->link then add DllDemoSimple2.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  : DllDemoSimple2Test.cpp
// purpose: tests DllDemoSimple2.DLL
// author : Neil Rieck
// notes  : https://neilrieck.net
//============================================================
#include <iostream>
#include "DllDemoSimple2.h" // get our function definitions
using std::cout;
using std::endl;
void main()
{   cout << "DllDemoSimple2Test" << endl;
    cout << "==================" << endl;
    cout << "2*20=" << SimpleDouble(20) << endl;
    cout << "3*30=" << SimpleTriple(30) << endl;
}
        
Back to Home