title: Runtime error R6030 and loading a dll through appinit_dlls registry
body: <p>I'm having a problem with injecting a dll into some processes through <strong>appinit_dlls</strong> registry key on windows 7, because the following error pops up, when process tried to execute:</p>
  
  <pre><code>Runtime Error!
  Program: C:\...
  
  R6030
  - CRT not initialized
  </code></pre>
  
  <p>I googled a lot about this kind of error, but nothing usefull found. I managed to create a environment, that provide this error.</p>
  
  <p>I have installed the latest trial version of <a href="http://www.lavasoft.com/thankyou_trial.php?source=trialpay_lb_total&amp;inter=trials&amp;internal=true" rel="nofollow">Lavasoft Ad-Aware Free Antivirus</a> on Windows 7.</p>
  
  <p>I'm using a registry key <strong>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\Appinit_dlls</strong> to load some dll into every process. This dll was build with <strong>Visual studio Express C++ 2010</strong> When some Lavasoft processes (e.g. AdAwareService.exe and AdAwareDesktop.exe) tries to execute, i'm getting the above error (Runtime Error R6030).</p>
  
  <p>I noticed, that if I build the same code in <strong>Visual Studio 2008</strong>, there is no error and dll gets loaded in the process.</p>
  
  <p>I even build an empty dll (release version) on both version (VS2008 and VS2010Express) with all default settings and the dll, that was build with VS2008 worked, but dll build with VS2010Express did NOT work and produce the above mentioned error.</p>
  
  <p>I was having similar problems also with VS2008 and some different application, so we moved to VS2010Express and apparently the same problem exists in different applications. When I debugged that problem with VS2008, it appears that dll stuck somewhere in function <strong>_DllMainCRTStartup</strong>.</p>
  
  <p>When I googled about the solution, some of most convincing ansvers were:</p>
  
  <ul>
  <li>Problem causes /ENTRY option in linker, but I'm not using any</li>
  <li>Combination of using AppInit: some system DLL (user32.dll?) just does a LoadLibrary from its DllMain which screws up initialization order.</li>
  <li>Some switches in VS, but I tried a lot of them with no success</li>
  </ul>
  
  <p>IMHO, there is some kind of race condition when loading my dll (or even an empty dll with default settings) into specific process...</p>
  
  <p>Can someone help me, because I don't have an idea, what more to try... Perhaps, it's just some setting in VS that will remove the problem...</p>
  
  <p>Thanks in advance</p>