共用方式為


dllexport、dllimport

Microsoft 特定的

dllexport 和 dllimport 儲存類別屬性是 Microsoft 專有的 C 和 C++ 語言擴充功能。 您可以使用它們在 DLL 中匯出和匯入函式、資料和物件。

__declspec( dllimport ) declarator 
__declspec( dllexport ) declarator

備註

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

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

函式的 dllexport 會以其裝飾名稱公開函式。 對於 C++ 函式,這包括名稱修飾 (Name Mangling)。 對於 C 函式或宣告為 extern "C" 的函式,其中包括根據呼叫慣例的平台專屬裝飾。 如果您不想要名稱裝飾,請使用 .def 檔案 (EXPORTS 關鍵字)。

當您宣告 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 特定的

請參閱

參考

__declspec

C++ 關鍵字