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 名稱裝飾規則的 C 函式或函式。 如需 C/C++程式代碼中名稱裝飾的詳細資訊,請參閱 裝飾名稱。
若要匯出未編碼的名稱,您可以使用定義區段中未編碼名稱EXPORTS的模組定義檔案連結.def。 如需詳細資訊,請參閱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;
如需詳細資訊,請參閱:
結束 Microsoft 特定內容