問題描述
我在堆損壞方面遇到了一些問題.使用 CreateWindowExW 函數時可以觀察到警告.我知道這通常是內存錯誤,但在這種情況下我怎么能找到它呢?在調用 CreateWindowExW 之前沒有新變量,我無法進入這個函數.這是代碼.
I have some problems with heap corruption. The warning can be observed while using CreateWindowExW function. I know that it is usually a memory error, but how could I search it out in such situation? There are no new variables before calling CreateWindowExW and I can't step into this function. Here is the code.
HWND GetMainWnd(HINSTANCE hInstance){
static HWND hWnd = NULL;
if (hWnd)
return hWnd;
RETURN_AT_ERROR(hInstance, NULL);
WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = MainWndProc;
wcex.hInstance = hInstance;
wcex.hCursor = ::LoadCursorW(NULL, IDC_ARROW);
wcex.lpszClassName = g_config->GetWndClass();
ATOM atom = ::RegisterClassExW(&wcex);
RETURN_AT_ERROR(atom != 0, NULL);
hWnd = ::CreateWindowExW(WS_EX_LEFT, g_config->GetWndClass(), 0, WS_POPUP | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 0, 0, 0, 0, 0, 0, hInstance, 0);
return hWnd;}
在這個字符串上
hWnd = ::CreateWindowExW(WS_EX_LEFT, g_config->GetWndClass(), 0, WS_POPUP | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 0, 0, 0, 0, 0, 0, hInstance, 0);
有一個警告信息框
Windows 在 drm.exe 中觸發了一個斷點.這可能是由于堆損壞,這表明 drm.exe 或任何它已加載的 DLL.這也可能是由于用戶按了 F12而 drm.exe 有焦點.輸出窗口可能有更多的診斷信息.
Windows has triggered a breakpoint in drm.exe. This may be due to a corruption of the heap, which indicates a bug in drm.exe or any of the DLLs it has loaded. This may also be due to the user pressing F12 while drm.exe has focus. The output window may have more diagnostic information.
我按繼續",它顯示
Unhandled exception at 0x77dae753 in app.exe: 0xC0000374: A heap has been corrupted.
然而,CreateWindowExW 返回一個非零值,并按原樣創建窗口...
However CreateWindowExW returns a non-zero value and window is created as it should be...
推薦答案
如上所述,堆損壞通常是在進程中加載??的某些 DLL/模塊已經發生真正損壞后檢測到的.從您的帖子看來,此問題是特定于 Windows 平臺的,因此我建議您使用 WinDBG/Pageheap 并找出實際發生內存損壞的位置.一篇關于堆內存損壞分析的非常好的文章可以在Advanced Windows Debugging, Author: By: Mario Hewardt; Daniel Pravat"Chapter 06
As pointed out above, heap corruption is often detected after the real corruption has already occurred by some DLL/module loaded within your process. From your post it looks like this issue is windows platform specific so I would suggest you to use WinDBG/Pageheap and find out where actual memory corruption is happening. One very very good article about heap memory corruption analysis can be found from the book "Advanced Windows Debugging, Author: By: Mario Hewardt; Daniel Pravat" Chapter 06
http://advancedwindowsdebugging.com/ch06.pdf
這篇關于使用 CreateWindowExW 時堆損壞的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!