MFC DLL Tutorial
   MFC regular Dll usage has decreased now a days to a large extent. People are now moving towards COM dlls. Though the COM Dlls' have a lot of advantages over regular Dlls' in MFC, the regular dlls are still being used by many developers.

   MFC DLL wizard provides options to create 3 kinds of DLLs. Regular DLL Statically linked to MFC, Regular DLL dynamically linked to MFC and MFC extension DLLs. This article uses MFC regular DLL Dynamically linked to MFC. The output produced by this option (dynamically linked) is a very small DLL. The statically linked DLLs will be of larger size, as they are built with the whole MFC libraries within themselves. 

   A MFC Dll can provide/export with functions, variable values, constants and classes. This article concentrates on exporting a function, which is the mostly used export in DLL.

MFC DLL - Building the DLL:

  1. Create an MFC AppWizard Dll. Choose the option of Regular MFC DLL - Dynamically Linked to MFC.
  2. After the application gets created, add a header file and a source file to the application. The article assumes the file names to be utilities.h, utilities.cpp.
  3. Enter a function declaration inside the header file utilities.h with the following syntax.
  4. __declspec(dllexport) int AddValues(int a, int b);

  5. Add the function definition inside the utilities.cpp file as follows.

  6. int AddValues(int a, int b)
    {
           return a+b;
    }


  7. Compile the MFC DLL application. This will produce a ProjectName.lib and ProjectName.dll in the debug folder. These two files are enough for using inside an application.

MFC DLL - Building the application:

  1. Create a new MFC AppWizard Executable application. Even a console application will be enough for using the MFC Dll.
  2. Copy the utilities.h into the project folder. Copy the ProjectName.lib and ProjectName.dll into debug folder of the project.
  3. In the source file of the application include the header file as #include "utilities.h".
  4. In Project Settings --> Link --> Library/Modules add Debug/ProjectName.lib. This will ensure linking of the necessary MFC Dll files.
  5. Call the AddValues function any where necesary.
  6. Build and run the application. The MFC Dll function will be used.

Close    To Top
  • Prev Article-Programming:
  • Next Article-Programming:
  • Now: Tutorial for Web and Software Design > Programming > c > Programming Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction