2016-04-20 3 views
0

Мой первый вопрос здесь: D Я пытаюсь создать DLL на C++, который сделает MessageBox, но я получаю эту странную ошибку: «Член MessageBox не определен». Я искал в Google, но ничего не помогло мне ...:/C++ DLL не вызывает MessageBox; «Member 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
Вот его/ее ответ;

Вы не можете вызвать любую функцию, которая может вызывать LoadLibrary из FreeLibrary или вы может создать цикл зависимостей в соответствии с документацией. Это также просто не имеет смысла. 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?