å¨VC++ä¸éæ©æ°å»ºä¸ä¸ªWin32 Dynamic-Link Libraryãéè¦å»ºç«ä¸ä¸ªc/c++ head fileåä¸ä¸ªc/c++ source file并å å
¥å·¥ç¨ã头æ件ä¸å
容为è¾åºå½æ°ç声æï¼æºæ件ä¸å
容为DllMainå½æ°åè¾åºå½æ°çå®ä¹ãä¸é¢æ¯ä¸ä¸ªæç®åçä¾åã
//dlldemo.h
#ifdef __cplusplus
#define EXPORT extern "C" __declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
EXPORT void CALLBACK DllFoo(void) ;
//dlldemo.c
#include <windows.h>
#include "dlldemo.h"
int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
return TRUE ;
}
EXPORT void CALLBACK DllFoo(void)
{
MessageBox(NULL,TEXT("This function is exported from a DLL"),TEXT("DllFoo"),MB_OK) ;
return ;
}
头æ件é¢å¤çä¸ç__declspecæ¯å¾®è½¯å¢å çâCæ©å±ç±»åå¨å±æ§â(C Extended Storage-Class Attributes)ï¼å®ææä¸ä¸ªç»åºçå®ä¾è¢«åå¨ä¸ºä¸ç§å¾®è½¯ç¹å®çç±»åå¨å±æ§ï¼å¯ä»¥ä¸ºthread,naked,dllimportædllexport. [MSDNåæï¼The extended attribute syntax for specifying storage-class information uses the __declspec keyword, which specifies that an instance of a given type is to be stored with a Microsoft-specific storage-class attribute (thread, naked, dllimport, or dllexport).] è¾åºå½æ°å¿
é¡»ææ为CALLBACKã DllMainæ¯dllçå
¥å£ç¹å½æ°ãä¹å¯ä»¥ä¸åå®ãDllMainå¿
é¡»è¿åTRUEï¼å¦åç³»ç»å°ç»æ¢ç¨åºå¹¶å¼¹åºä¸ä¸ªâå¯å¨ç¨åºæ¶åºéâ对è¯æ¡ã ç¼è¯é¾æ¥åï¼å¾å°å¨æé¾æ¥åºæ件dlldemo.dllåè¾å
¥åºæ件dlldemo.libã
温馨提示:内容为网友见解,仅供参考