Click here to Skip to main content
15,883,883 members
Articles / Desktop Programming / MFC

Regular DLL Tutor For Beginners

Rate me:
Please Sign up or sign in to vote.
4.82/5 (90 votes)
15 Apr 20049 min read 569.3K   8.1K   313  
Regular Win32 and MFC DLL tutorial for beginners.
/*****************************************************************************************
   File name: DLLCode.h

   This file contains all the DLL interfacing object declarations, in this example: a
   class object, a global function object, and a global integer variable. 

   Notice: we use the same header file for compiling the .dll and the .exe (application).
   This header file defines a macro which export the target DLL objects if we are building
   a DLL, otherwise it import the DLL objects into an application which uses the DLL. If
   we define DLLDIR_EX (a preprocessor identifier), then the preprocessor define macro
   DLLDIR (a mnemonic for DLL, import/export, Direction) becomes an export instruction,
   otherwise its an import instruction by default. 
*****************************************************************************************/

#ifdef DLLDIR_EX
   #define DLLDIR  __declspec(dllexport)
#else
   #define DLLDIR  __declspec(dllimport)
#endif

// This prevent the C++ compiler from using decorated (modified) names for the functions 
extern "C" { 
       void DLLDIR DLLfun1(char*);
       int  DLLDIR DLLfun2(int);
};

extern int  DLLDIR DLLArg;

class DLLDIR Dllclass
{
   public:
      Dllclass();          // Class Constructor
      ~Dllclass();         // Class destructor
      int Add(int, int);   // Class function Add
      int Sub(int, int);   // Class function Subtract
      int Arg;             // Warming: you should not import class variables
                           // since the DLL object can be dynamically unloaded.
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions