Debugging the dreaded 'Application has failed to initialize' error
I occasionally run into this error when trying run an executable I've built on windows, but I have no idea what causes it or how to fix it. With the normal MSVC debugger, it just pops up a dialog and exits with no chance to do anything or look at anything. I've managed to at least catch something and get a stack trace with the Microsoft console debugger, but I have no idea what to look at from here. It seems to be failing oddly within ntdll.dll before ever getting to main function of my program or running any of my code.
C:\> cdb bugrepro
Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.
CommandLine: bugrepro.exe
Symbol search path is: C:\SYMBOLS
Executable search path is:
ModLoad: 00400000 00447000 bugrepro.exe
ModLoad: 7c900000 7c9af000 ntdll.dll
ModLoad: 7c800000 7c8f6000 C:\WINDOWS\system32\kernel32.dll
ModLoad: 10000000 1002a000 glut32.dll
ModLoad: 5ed00000 5edcc000 C:\WINDOWS\system32\OPENGL32.dll
ModLoad: 77c10000 77c68000 C:\WINDOWS\system32\msvcrt.dll
ModLoad: 77dd0000 77e6b000 C:\WINDOWS\system32\ADVAPI32.dll
ModLoad: 77e70000 77f02000 C:\WINDOWS\system3开发者_如何学C2\RPCRT4.dll
ModLoad: 77fe0000 77ff1000 C:\WINDOWS\system32\Secur32.dll
ModLoad: 77f10000 77f59000 C:\WINDOWS\system32\GDI32.dll
ModLoad: 7e410000 7e4a1000 C:\WINDOWS\system32\USER32.dll
ModLoad: 68b20000 68b40000 C:\WINDOWS\system32\GLU32.dll
ModLoad: 73760000 737ab000 C:\WINDOWS\system32\DDRAW.dll
ModLoad: 73bc0000 73bc6000 C:\WINDOWS\system32\DCIMAN32.dll
ModLoad: 76b40000 76b6d000 C:\WINDOWS\system32\WINMM.dll
(64c.7b4): Unknown exception - code c0000022 (first chance)
(64c.7b4): Unknown exception - code c0000022 (!!! second chance !!!)
eax=0012fc54 ebx=00000000 ecx=0012fc80 edx=7c90e4f4 esi=7ffd8000
edi=c0000022
eip=7c96478e esp=0012fc54 ebp=0012fca4 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
ntdll!RtlRaiseStatus+0x26:
7c96478e c9 leave
0:000> ~k
ChildEBP RetAddr
0012fca4 7c93f14e ntdll!RtlRaiseStatus+0x26
0012fd1c 7c90e437 ntdll!_LdrpInitialize+0x241
00000000 00000000 ntdll!KiUserApcDispatcher+0x7
0:000>
Anyone have any suggestions of where to go from here in debugging this?
Following up on Moron's answer, You should run Process Monitor.
This tool will tell you exactly what your process does, and which files it tried (and likely at least for one failed) to load, and what the errors are.
It does more than this, and for any process troubleshooting, it's an amazing time-saver.
Usually the "Application has failed to initialize" error is related to missing imports from dlls; combined with the 0xC0000022 it may mean that a dll needed by your application cannot be loaded because of an access denied error (maybe the user hasn't got the rights to open/execute that file).
Try running with the dependency walker. http://dependencywalker.com/
It does static analysis of dependencies, and it can also trace through the startup of an application.
If I recall correctly, exception code c0000022 stands for Access Denied. Usually, it means Windows blocked access to a resource, like a domain controller or a driver.
You haven't specified the nature of your application, but it is evident from the stack dump that it deals with 3D/OpenGL devices. Perhaps your issue lies with a misconfigured driver or library. I suggest testing on another machine and/or re-installing your drivers.
精彩评论