Creating DLL and Using it 600459– Visual Programming Anna University lab manual download fourth semester - Computer Programming


C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Saturday, January 29, 2011

Creating DLL and Using it 600459– Visual Programming Anna University lab manual download fourth semester

Creating DLL and Using it 600459– Visual Programming Anna University lab manual download fourth semester


            To write a VC++ program to develop DLL and export the function using MFC (.dll) and use the same function in the client program using MFC (.exe).

Logical Description:

            DLL is a file on disk with a DLL extension consisting of global data, compiled functions, and resources that becomes part of our process. It is compiled to load at a preferred base address, and if there is no conflict with other DLLs, the file gets mapped to the same virtual address in our process. The DLL consists of exported function, and the client program imports those exported functions. Windows matches up the imports and exports when it loads the DLL.

  • Classes are build-time modular
  • DLLs are runtime modular

Client programs can load and link our DLL very quickly when they run.

            This program is to create SayHello( ) in the DLL and exported this function to any client program to use it. Also this DLL is included in the client program to use the SayHello( ).

Steps to build the MyDll and TestDll application:

DLL Server – MyDll.dsw

  1. Run VC++ MFC AppWizard to create (.dll)..\MyDll

  1. Select Regular DLL using Shared MFC DLL and click finish.

  1. Goto Class View and right click the MyDll class and choose New Class.

  1. Now choose the class type to be the Generic Class and type the class name as CMyClass then click OK.

  1. Then add member function to the CMyClass by right clicking and type,

    1. function type as CString 
    2. function name as SayHello(CString strName);
    3. access type is public

  1. Add the function definition in MyClass.cpp

CString CMyClass:: SayHello(CString strName)
          return “Hello “ + strName;

  1. To call the DLL function from an external application we have to prefix the function with the signature in MyClass.h with “_declspec(dllexport)”. Add the following boldface code to the following statements in MyClass.h file,

_declspec(dllexport) CString SayHello(CSTring strName);
_declspec(dllexport) CMyClass();
_declspec(dllexport) virtual ~CMyClass();

  1. Compile the code without executing.

DLL Client – TestDll.dsw

  1. Run the VC++ MFC AppWizard(.exe) to develop a dialog based application ..\Testdll.dsw

  1. The resource editor will be enabled once finishing the project and add one static control, one edit control and one button control.

  1. Add the id for the edit control IDC_NAME and add the member variable as m_sName and type as CString by using the class wizard.

  1. Use the class wizard to map the message OnOk function for IDOK in the TestDllDlg class.

  1. Now edit the code on TestDllDlg.cpp

Void CTestDllDlg::OnOk()
          CMyClass objMyClass;
CString str = objMyClass.SayHello(m_sName);

  1. Now add the entire path of the MyDll server header file in TestDllDlg.h

#include “E:\Exercise\MyDll\MyClass.h”
  1. Click the project menu and select the settings and click on the link tab and type the entire path of the “MyDll.lib” file in the Object/Library Modules text boxes as,


  1. Now copy the “MyDll.dll” in the MyDll Debug folder into the TestDll folder.

  1. Build the project and execute it.

No comments:

Post a Comment