使用CreateWindowExW时堆损坏 [英] Heap Corruption while using CreateWindowExW

查看:934
本文介绍了使用CreateWindowExW时堆损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  HWND GetMainWnd(HINSTANCE hInstance){
static HWND hWnd =
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,hInstance,0);



$ b

  hWnd = :: CreateWindowExW(WS_EX_LEFT,g_config-> GetWndClass(),0,WS_POPUP | WS_MINIMIZEBOX | WS_CLIPCHILDREN,0,0,0, 0,0,hInstance,0); 

有一个警告消息框


Windows在drm.exe中触发了断点。这可能是由于堆的
损坏,这表示drm.exe或其加载的任何
DLL中的错误。这也可能是由于用户按下F12
,而drm.exe有焦点。输出窗口可能有更多诊断
信息。


我按继续,它显示

  app.exe中0x77dae753处的未处理异常:0xC0000374:堆已损坏。 

但是CreateWindowExW返回一个非零值,并创建窗口,因为它应该是... <正如上面指出的,在进程内加载的某些DLL /模块已经发生了真正的损坏之后,堆损坏通常被检测到。从你的帖子看起来像这个问题是Windows平台具体所以我建议你使用WinDBG / Pageheap,并找出实际的内存损坏发生在哪里。关于堆内存损坏分析的一篇非常好的文章可以在Advanced Windows Debugging,作者:Mario Hewardt; Daniel Pravat第06章中找到。



http://advancedwindowsdebugging.com/ch06.pdf


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;}

On this string

hWnd = ::CreateWindowExW(WS_EX_LEFT, g_config->GetWndClass(), 0, WS_POPUP | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 0, 0, 0, 0, 0, 0, hInstance, 0);

there is a warning message box

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.

I press "Continue" and it shows

Unhandled exception at 0x77dae753 in app.exe: 0xC0000374: A heap has been corrupted.

However CreateWindowExW returns a non-zero value and window is created as it should be...

解决方案

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时堆损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆