使用VisualStudio2007
兩個專案,
一個編譯後為DLL (MFC->Regular DLL using shared MFC DLL)
另一個為Interface (MFC->Dialog Based)
--------------------------------------------------------------
DLL專案 (testDLL_9_26B.sln)
1.add : testDLL_9_26B_API.h、testDLL_9_26B_API.cpp
2.testDLL_9_26B_API.h 新增
testDLL_9_26B_API int Add(int a, int b);
testDLL_9_26B_API int Del(int a, int b);
3.testDLL_9_26B_API.cpp
#include "testDLL_9_26B_API.h"
testDLL_9_26B_API int Add(int a, int b){
return (a+b);
}
testDLL_9_26B_API int Del(int a, int b){
return (a-b);
}
-----------------------------------------------------------
Interface專案 (testDLL_Interface)
1.add : testDLL_InterfaceDlg.h、testDLL_InterfaceDlg.cpp
2.testDLL_InterfaceDlg.h中新增
HMODULE m_hDLL;
void initDLL();
bool LoadDll(const TCHAR* InterfaceDll);
typedef int (*pfAdd)(int a, int b);
typedef int (*pfDel)(int a, int b);
3.IDD_TESTDLL_INTERFACE_DIALOG 中新增2個Static Text,取名為IDC_STATIC1、IDC_STATIC2
4.testDLL_InterfaceDlg.cpp中新增
#include "testDLL_InterfaceDlg.h"
bool CtestDLL_InterfaceDlg::LoadDll (const TCHAR* InterfaceDll)
{...
}
--------------------------------------------------------------
把DLL專案編譯完的DLL放到Interface專案譯後的exe資料夾中,即可執行
SOURCE CODE Download
https://docs.google.com/viewer?a=v&pid=explorer&chrome=true&srcid=0B88tKfa7qpFPZWU3Yzk0NzctMmIzOC00MGM3LTllYmItNjM5ZmQzNjIwYzNj&hl=en
留言列表