3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
code blocks 撰寫DLL和動態載入使用   資料來源:          01.https://helloacm.com/tutorial-create-a-sample-dll-project-using-codeblocks-ide-in-cc/          02.http://www.infernodevelopment.com/simple-c-dll-loading-message-box GITHUB專案檔:https://github.com/jash-git/code-blocks-DLL-   DLL_H #ifndef __MAIN_H__ #define __MAIN_H__ #include /*  To use this exported function of dll, include this header  *  in your project.  */ #ifdef BUILD_DLL     #define DLL_EXPORT __declspec(dllexport) #else     #define DLL_EXPORT __declspec(dllimport) #endif #ifdef __cplusplus extern “C” { #endif void DLL_EXPORT SomeFunction(const LPCSTR sometext); #ifdef __cplusplus } #endif #endif // __MAIN_H__   DLL_C #include “main.h” //資料來源:https://helloacm.com/tutorial-create-a-sample-dll-project-using-codeblocks-ide-in-cc/ // a sample exported function void DLL_EXPORT SomeFunction(const LPCSTR sometext) {     MessageBoxA(0, sometext, “DLL Message”, MB_OK | MB_ICONINFORMATION); } extern “C” DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {     switch (fdwReason)     {         case DLL_PROCESS_ATTACH:             // attach to process             // return FALSE to fail DLL load             break;         case DLL_PROCESS_DETACH:             // detach from process             break;         case DLL_THREAD_ATTACH:             // attach to thread             break;         case DLL_THREAD_DETACH:             // detach from thread             break;     }     return TRUE; // succesful }   EXE_C #include //– //http://www.infernodevelopment.com/simple-c-dll-loading-message-box #include typedef  void (*FuncPtr)(LPCTSTR); //– using namespace std; int main() {     cout << “Hello world!” << endl;     FuncPtr myDllFunc;     BOOL linkSuccessFlag = FALSE, fFreeResult;     HINSTANCE hinstLib = LoadLibrary(“CB_DLL.dll”);     if (hinstLib != NULL) {         myDllFunc = (FuncPtr) GetProcAddress(hinstLib, “SomeFunction”);         if (myDllFunc != NULL)         {             linkSuccessFlag = TRUE;             myDllFunc(“Hello, World! by jash”);         }         fFreeResult = FreeLibrary(hinstLib);     }     system(“pause”);     return 0; }      

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦