2016-04-20 54 views
0

我的第一個問題在這裏:D 我想在C++中製作一個DLL,它將製作一個MessageBox,但我得到這個奇怪的錯誤:「成員MessageBox沒有定義」。我搜索在谷歌,但沒有幫助我...:/不調用MessageBox的C++ DLL; 「成員MessageBox沒有被定義」

這裏是我的代碼:

#include<windows.h> 

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 
{ 
    MessageBox(0, "DLL Loaded", "SUCCESS STATUS", MB_OK); //here is the error :(
    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 
} 

任何想法?我從來沒有過:(

回答

2

類似的問題,你可以看到你的問題在這裏得到解答:DllMain() routine and MessageBox() function
通過rerun
這是他/她的回答;

不能調用,可以調用FreeLibrary或您的調用LoadLibrary任何功能可能會創建一個依賴關係循環根據文檔。它也只是沒有意義。Dll main應該只用於做一些非常有限的初始化它是一個入口點到您的庫不是邏輯應該執行的地方

During initial process startup or after a call to LoadLibrary, the system scans the list of loaded DLLs for the process. For each DLL that has not already been called with the DLL_PROCESS_ATTACH value, the system calls the DLL's entry-point function. This call is made in the context of the thread that caused the process address space to change, such as the primary thread of the process or the thread that called LoadLibrary. Access to the entry point is serialized by the system on a process-wide basis. Threads in DllMain hold the loader lock so no additional DLLs can be dynamically loaded or initialized.

你可以看到這個問題來理解爲什麼你不應該這樣做; Loading a dll from a dll?