Search This Blog

Wednesday, December 10, 2008

MFC DLL with wrapper

  1. Create a MFC DLL with the project name "MyDLL"
  2. Add a new class with class name "CMyClass" with class type "Generic Class".
  3. Edit the following files as the instruction given below.

// Add the following lines in MyClass.h
class CMyClass
{
public:
int Add(int a , int b); //add this Line
};


// Add the following lines in MyDLL.h
#include "MyClass.h"
#ifndef EXP
#define EXP extern "C" __declspec( dllexport )
#endif
#define APPPTR ((CMyDLLApp*) AfxGetApp())
class CMyDLLApp : public CWinApp
{
public:
CMyClass m_MyObj; //add this line
};


// Add the following lines in MyClass.cpp:
#include "stdafx.h"
#include "MyDLL.h"
#include "MyClass.h"
int CMyClass::Add(int a , int b)
{
return(a+b);
}



// Add the following lines in MyDLL.cpp
#include "stdafx.h"
#include "MyDLL.h"
#include "MyClass.h"

EXP int egAdd(int a, int b)
{
int c=0;
c= APPPTR->m_MyObj.Add(a,b);
return c;
}

No comments: