看板 MaRoon
作者 標題 C++ 製作 DLL (隱式連結)
時間 2015年02月02日 Mon. AM 07:10:59
DLL_project 目錄有 dll.h 和 dllmain.cpp 檔
流程: 宣告 → 實作
dll.h 介面宣告
原始碼:
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
#define DLLIMPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif
extern "C" __declspec(dllexport) void HelloWorld(void);
extern "C"{
__declspec(dllexport) double AddNumbers(double a, double b);
}
#endif
dllmain.cpp 實作
原始碼:
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
#include <iostream>
extern "C" __declspec(dllexport) void HelloWorld(){
MessageBox(0, "Hello World from DLL!\n","Hi",MB_ICONINFORMATION);
}
extern "C" __declspec(dllexport) double AddNumbers(double a, double b){
return a+b;
}
說明:
.cpp 編譯完成後目錄下即會產生 .dll 檔
--
※ 作者: KTR150Fi 時間: 2015-02-02 07:10:59
※ 看板: MaRoon 文章推薦值: 0 目前人氣: 0 累積人氣: 296
回列表(←)
分享