c – 使用CreateWindowExW时堆损坏

我有一些堆损坏的问题.使用CreateWindowExW函数时可以观察到警告.我知道这通常是一个内存错误,但我怎么能在这种情况下搜索它?在调用CreateWindowExW之前没有新变量,我无法进入此函数.这是代码.

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 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返回一个非零值,并创建窗口,因为它应该…

如上所述,在您的进程中加载​​的某些DLL /模块已经发生实际损坏之后,通常会检测到堆损坏.从你的帖子看起来这个问题是特定于Windows平台的,所以我建议你使用WinDBG / Pageheap并找出实际内存损坏发生的地方.关于堆内存损坏分析的一篇非常好的文章可以在“高级Windows调试,作者:作者:Mario Hewardt; Daniel Pravat”一书中找到.

http://advancedwindowsdebugging.com/ch06.pdf

相关文章
相关标签/搜索