建立和使用DLL

2021-06-07 17:11:14 字數 851 閱讀 5695

首先建立個dll工程(win32控制台——dll工程)

新增標頭檔案和cpp檔案,如下:

#ifndef __dll_test_h__ 

#define __dll_test_h__

class __declspec(dllexport)

ctest

;#endif

#include "dll_test.h"

#include ctest::ctest()

ctest::~ctest()

void ctest::print()

再新建乙個測試工程,在工程中設定好附加依賴生成的lib檔案,新增測試**:

#include#include "dll_test.h"

int main()

完成。

做完後,分析一下,其實關鍵就在於這兩句:

class __declspec(dllexport)  ctest{};

msdn中的說明是:they enable you to export and import functions, data, and objects to and from a dll.

另:declaring functions as 

dllexport

eliminates the need for a module-definition (.def) file,

也就是說使用dllexport後,就不用在dll工程中建立.def檔案作宣告了,因為它代替了__export

關鍵字

DLL的建立和使用

我們將建立的第一種型別的庫是動態鏈結庫 dll 使用 dll 是一種重用 的絕佳方式。您不必在自己建立的每個程式中重新實現同一例程,而只需對這些例程編寫一次,然後從需要該功能的應用程式引用它們即可。本演練涵蓋以下內容 建立新的動態鏈結庫 dll 專案。向動態鏈結庫新增類。建立引用動態鏈結庫的應用程式...

C 中建立和使用dll

c 中建立和使用dll比c 中方便多了!c 中沒有了c 中的.h標頭檔案,確實省了很多麻煩。建立乙個dll using system using system.collections.generic using system.text namespace classlibrary1 非常簡單地就建立...

C 中dll的建立和使用

一 dll的建立 1 新建專案類庫 2 編寫需要使用的函式 using system using system.collections.generic using system.linq using system.text using system.threading.tasks using sys...