C++ : Class로 만든 DLL Export 및 Import
프로젝트 만들 때 솔루션 디렉토리를 생성하고 Dll 프로젝트와 Test Dll 프로젝트를 생성한다 Test Dll 프로젝트는 MFC 응용 프로그램에서 다이얼로그 기반만 설정하고 마침한다 Dll 프로젝트는 MFC 확장 DLL만 설정하고 마침한다 Dll 프로젝트에서 Dll과 App에서 사용할 공용 헤더를 추가한다 Dll.h class A { public: virtual int AddInteger(int A, int B) = 0; virtual void destroy() = 0; }; Dll.cpp #include "stdafx.h" #include "Dll.h" #include <iostream> #ifdef _DEBUG #define new DEBUG_NEW #endif using namespace std; class B : public A { public: B() { cerr << "B constructor\n"; } ~B() { cerr << "B destructor\n"; } int AddInteger(int C, int D) { return C+D; } void destroy() { delete this; } }; extern "C" __declspec ( dllexport ) A* create_b () { return new B; } Test_App의 Dlg.cpp 에서 Dll.h 파일을 include 하고 테스트용으로 만든 버튼에 HINSTANCE hDll = NULL; hDll = LoadLibrary(L"Dll.dll"); if(hDll == NULL) { OutputDebugString(L"dll load fail...
댓글
댓글 쓰기