源码

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

(0)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/c-shiyongcreatewindowexwshiduisunhuai.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9月 19, 2019 at 12:20 下午

热评文章