我已经使用 VS2008 向导创建了一个 MFCApp。在我的应用程序的“InitInstance()”中,我正在调用“LoadLibraryA()”方法,因为我需要加载一些 dll 文件。但是一旦我调用“LoadLibraryA()”,它就会再次调用我的应用程序的“InitInstance()”,因此它变成了无限递归的东西。有什么我做错了吗?
// CLoader_MFCApp initialization
BOOL CLoader_MFCApp::InitInstance()
{
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinAppEx::InitInstance();
SetRegistryKey(_T("MyApp"));
HMODULE hm = LoadLibraryA("./abc/def.dll");
// after above line InitInstance() gets called again
// more code
return FALSE;
}
调用堆栈:
MyApp.exe!CLoader_MFCApp::InitInstance() C++
CORE.dll!InternalDllMain(HINSTANCE__ *, unsigned long, void *) C++
CORE.dll!__DllMainCRTStartup(void *, unsigned long, void *) C
CORE.dll!_DllMainCRTStartup(void *, unsigned long, void *) C
ntdll.dll!_LdrpCallInitRoutine@16()
ntdll.dll!_LdrpRunInitializeRoutines@4()
ntdll.dll!_LdrpLoadDll@24()
ntdll.dll!_LdrLoadDll@16()
kernel32.dll!_LoadLibraryExW@12()
kernel32.dll!_LoadLibraryExA@12()
kernel32.dll!_LoadLibraryA@4()
MyApp.exe!CLoader_MFCApp::InitInstance() C++
mfc90.dll!AfxWinMain(HINSTANCE__ *, HINSTANCE__ *, char *, int) C++
MyApp.exe!__tmainCRTStartup() C
kernel32.dll!_BaseProcessStart@4()
“Def.dll”是任何其他 dll,与 MyApp 完全无关。在这种情况下,我正在尝试加载另一个 dll “CORE.dll”
我所能弄清楚的是,我在 InitInstance 例程结束之前调用了 LoadLibrary。是否有在 InitInstance 之后调用的任何其他(可覆盖)方法???如果是这样,我可以尝试将 LoadLibrary 调用移至该方法...