簡略紀錄使用方式,後續在新增說明

 

<要製作的dll檔>

CountMath.h:

新增要被使用的函式

extern "C" {  
    __declspec(dllexport) void AddNumber(int a, int b);  

 

CountMath.cpp:

實做要使用的函式

__declspec(dllexport) void AddNumber(int a, int b)
{    
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    CString str;
    str.Format("%d",(a+b));
    AfxMessageBox(str);

 

編譯時選用:Win32 Release

會在Relesae資料夾中生成 .dll 及 .lib檔

 

 

<要使用dll檔的專案>

在專案資料夾內創兩個資料夾Include及Lib,分別將

CountMath.h 放到Include資料夾裡、

CountMath.lib 放到Lib資料夾裡。

將CountMath.dll 放到專案生成exe檔的資料夾內

 

Test.h:

#include "Include\\CountMath.h"
#pragma comment(lib,"Lib\\CountMath.lib")

 

TestDig.cpp:

在使用dll函式的地方,直接叫用該函式名稱及帶入所需參數即可

void CTestDlg::OnOk()
{
    // TODO: Add your control notification handler code here
    int a=2,b=3;
    AddNumber(a,b);
    
}

 

如此Test 就可以動態使用CountMath 中的 AddNumber函式

 

 

 

 

arrow
arrow
    全站熱搜

    fiend1120 發表在 痞客邦 留言(0) 人氣()