我寫了一個非常小的64位應用程序,它在乾淨的Windows Vista x64安裝上崩潰。它在安裝了Visual Studio 2008的開發計算機(Windows 7 64位)上運行平穩。爲什麼我的64位C++應用程序崩潰?
64位C++應用程序(非託管)由32位.NET應用程序啓動,並在出現訪問衝突錯誤後立即崩潰。這是事件查看器說:
Faulting application MaxTo64.exe, version 0.0.0.0, time stamp 0x49a41d9e,
faulting module USER32.dll, version 6.0.6001.18000, time stamp 0x4791adc5,
exception code 0xc0000005, fault offset 0x00000000000236d6, process id 0x82c,
application start time 0x01c996a346a3e805.
MaxTo64.exe
0.0.0.0
49a41d9e
USER32.dll
6.0.6001.18000
4791adc5
c0000005
00000000000236d6
82c
01c996a346a3e805
我已經安裝了VC2008可再發行(2008年86,2008年64位,2008 SP1 x86和2008 SP1 64位),所以這不應該成爲問題。 編輯:可能值得一提的是,在安裝vcredist-package之前,它會以不同的方式崩潰,並且存在並行配置錯誤。
我是一個C++ n00b,所以我真的不知道在哪裏看下。
編輯:Windows調試工具的輸出。
CommandLine: "C:\Program Files (x86)\MaxTo\MaxTo64.exe" maxto_a_do_run_run
Symbol search path is: *** Invalid ***
****************************************************************************
* Symbol loading may be unreliable without a symbol search path. *
* Use .symfix to have the debugger choose a symbol path. *
* After setting your symbol path, use .reload to refresh symbol locations. *
****************************************************************************
Executable search path is:
ModLoad: 00000001`3f2f0000 00000001`3f30b000 MaxTo64.exe
ModLoad: 00000000`77160000 00000000`772e0000 ntdll.dll
ModLoad: 00000000`77030000 00000000`7715b000 C:\Windows\system32\kernel32.dll
ModLoad: 00000001`80000000 00000001`80011000 C:\Program Files (x86)\MaxTo\Hooker.dll
ModLoad: 00000000`76f60000 00000000`7702d000 C:\Windows\system32\USER32.dll
ModLoad: 000007fe`fed70000 000007fe`fedd3000 C:\Windows\system32\GDI32.dll
ModLoad: 000007fe`fea20000 000007fe`feb28000 C:\Windows\system32\ADVAPI32.dll
ModLoad: 000007fe`fe850000 000007fe`fe98f000 C:\Windows\system32\RPCRT4.dll
ModLoad: 000007fe`fd8b0000 000007fe`fe502000 C:\Windows\system32\SHELL32.dll
ModLoad: 000007fe`fef70000 000007fe`ff00c000 C:\Windows\system32\msvcrt.dll
ModLoad: 000007fe`feee0000 000007fe`fef53000 C:\Windows\system32\SHLWAPI.dll
(3a4.964): Break instruction exception - code 80000003 (first chance)
*** ERROR: Symbol file could not be found. Defaulted to export symbols for ntdll.dll -
ntdll!DbgBreakPoint:
00000000`771a4ea0 cc int 3
0:000> g
ModLoad: 000007fe`fe780000 000007fe`fe7ad000 C:\Windows\system32\IMM32.DLL
ModLoad: 000007fe`ff010000 000007fe`ff111000 C:\Windows\system32\MSCTF.dll
ModLoad: 000007fe`feed0000 000007fe`feedd000 C:\Windows\system32\LPK.DLL
ModLoad: 000007fe`fede0000 000007fe`fee7a000 C:\Windows\system32\USP10.dll
ModLoad: 000007fe`fc150000 000007fe`fc349000 C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6001.18000_none_152e7382f3bd50c6\comctl32.dll
(3a4.964): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\system32\USER32.dll -
USER32!DisableProcessWindowsGhosting+0x1a:
00000000`76f836d6 66f2af repne scas word ptr [rdi]
*** ERROR: Module load completed but symbols could not be loaded for MaxTo64.exe
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\system32\kernel32.dll -
在這一點上,調用堆棧:
USER32!DisableProcessWindowsGhosting+0x1a
USER32!ChangeWindowMessageFilter+0x12d
USER32!RegisterClassExW+0x25
MaxTo64+0x11e4
MaxTo64+0x1075
MaxTo64+0x1920
kernel32!BaseThreadInitThunk+0xd
ntdll!RtlUserThreadStart+0x21
這似乎是在MyRegisterClass,它看起來像這樣:
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAXTO64));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
編輯:原來,問題是我自己愚蠢的錯誤。顯然,WNDCLASSEX結構中有一個字段未正確初始化。奇怪的是,這在Vista上崩潰,但在Windows 7上崩潰。添加這個可以解決問題。
wcex.lpszMenuName = NULL;
如果你沒有明確地清零一個結構,它的內容是隨機數 - 在聲明後嘗試一個ZeroMemory – 2009-02-24 20:23:35