dllexport
, dllimport
Microsoft 特定的
dllexport
和 dllimport
儲存類別屬性是 C 和 C++ 語言的 Microsoft 特定擴充功能。 您可以使用它們在 DLL 中匯出和匯入函式、資料和物件。
語法
__declspec( dllimport )
declarator
__declspec( dllexport )
declarator
備註
這些屬性明確定義其用戶端的 DLL 介面 (可以是可執行檔或另一個 DLL)。 將函式宣告為 dllexport
,可免除模組定義 () .def
檔案的需求,至少與匯出函式的規格有關。 屬性 dllexport
會 __export
取代 關鍵字。
如果類別標示 __declspec(dllexport)
為 ,則類別階層中類別範本的任何特製化都會隱含地標示為 __declspec(dllexport)
。 這表示類別範本會明確具現化,而且必須定義類別的成員。
dllexport
的 函式會公開具有裝飾名稱的函式,有時稱為「名稱管理」。 若為 C++ 函式,裝飾名稱會包含編碼類型和參數資訊的額外字元。 宣告為 extern "C"
的 C 函式或函式包含以呼叫慣例為基礎的平臺特定裝飾。 不會將名稱裝飾套用至使用呼叫慣例的 __cdecl
匯出 C 函式或 C++ extern "C"
函式。 如需 C/C++ 程式碼中名稱裝飾的詳細資訊,請參閱 裝飾名稱。
若要匯出未編碼的名稱,您可以使用模組定義 (.def
) 檔案連結,以定義區段中未取消編碼的名稱 EXPORTS
。 如需詳細資訊,請參閱EXPORTS
。 匯出未指定名稱的另一 #pragma comment(linker, "/export:alias=decorated_name")
種方式是在原始程式碼中使用 指示詞。
當您宣告 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 特定