title: In MFC APP, if I call "LoadLibraryA" from "InitInstance", it calls "InitInstance" again and again
body: <p>I have created an MFCApp using VS2008 wizard. Inside my application's "InitInstance()" I'm calling "LoadLibraryA()" method as I need to load a few dll files. But as soon as I call "LoadLibraryA()", it again calls "InitInstance()" of my application and hence it becomes a infinite recursion stuff. Is there something I'm doing wrong?</p>
  
  <pre><code>// CLoader_MFCApp initialization
  BOOL CLoader_MFCApp::InitInstance()
  {
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&amp;InitCtrls);
    CWinAppEx::InitInstance();
    SetRegistryKey(_T("MyApp"));
  
    HMODULE hm = LoadLibraryA("./abc/def.dll");
    // after above line InitInstance() gets called again
  
    // more code
    return FALSE;
  }
  </code></pre>
  
  <p>Call Stack:</p>
  
  <pre><code>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()  
  </code></pre>
  
  <p>"Def.dll" is any other dll and completely unrelated from MyApp. In this case, I'm trying to load another dll "CORE.dll"</p>
  
  <p>All I can figure out is that I'm calling LoadLibrary before InitInstance routine is over. Is there any other (overridable) method which is called after InitInstance??? If so, I can try moving LoadLibrary calls to that method...</p>