共用方式為


dllexport dllimport

Microsoft 專有的

dllexport 和 dllimport 儲存類別屬性是 Microsoft 特定副檔名為 C 和 C++ 語言。 您可以使用它們來匯出和匯入函式、資料和物件來回 DLL。

__declspec( dllimport ) declarator __declspec( dllexport ) declarator

備註

這些屬性明確定義 DLL 的介面給用戶端,可以是可執行檔或另一個 DLL。 宣告函式,當 dllexport 不需要模組定義 (.def) 檔,至少有關輸出的規格運作。 dllexport 屬性被取代 __export 關鍵字。

如果類別已標記為 declspec declspec(dllexport),類別樣板的特製化在類別階層架構的隱含標記成 declspec declspec(dllexport)。 這表示類別樣板的明確具現化,而類別的成員必須定義。

函式的dllexport 公開與其裝飾名稱的函式。 對於 C++ 函式,包括函式名稱改變 (Name Mangling)。 對於宣告為 extern 「C」的 C 函式或函式,包括根據呼叫慣例的平台專屬裝飾。 如果您不想要裝飾名稱,請使用 .def 檔 (匯出 關鍵字)。

當您宣告 dllexport 或 dllimport時,您必須使用 擴充屬性語法 與 __declspec 關鍵字。

範例

// Example of the dllimport and dllexport class attributes
__declspec( dllimport ) int i;
__declspec( dllexport ) void func();

或者,讓程式碼更容易讀取,您可以使用巨集定義:

#define DllImport   __declspec( dllimport )
#define DllExport   __declspec( dllexport )

DllExport void func();
DllExport int i = 10;
DllImport int j;
DllExport int n;

如需詳細資訊,請參閱:

END Microsoft Specific

請參閱

參考

__declspec

C + + 關鍵字