dllexportdllimport

Microsoft 特定的

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

語法

__declspec( dllimport ) declarator
__declspec( dllexport ) declarator

備註

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

如果類別標示為 __declspec(dllexport),則類別階層中類別範本的任何特製化都會隱含地標示為 __declspec(dllexport)。 這表示類別範本已明確具現化,且必須定義類別的成員。

dllexport 的函式會公開函式及其裝飾名稱,有時稱為「名稱修飾」。 針對 C++ 函式,裝飾名稱包含編碼型別和參數資訊的額外字元。 C 函式或宣告為 extern "C" 的函式遵循 C 名稱裝飾規則的。 如需 C/C++ 程式碼中名稱裝飾的詳細資訊,請參閱裝飾名稱 (部分機器翻譯)。

若要匯出未裝飾名稱,則連結方式是使用在 EXPORTS 區段中定義未裝飾名稱的模組定義 (.def) 檔。 如需詳細資訊,請參閱EXPORTS。 匯出未裝飾名稱的另一種方式是在原始程式碼中使用 #pragma comment(linker, "/export:alias=decorated_name") 指示詞。

當您宣告 dllexportdllimport 時,您必須使用擴充屬性語法 (部分機器翻譯) 和 __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
關鍵字