gpt4 book ai didi

c++ - 为什么 CWnd::CreateEx 无法创建我的窗口?

转载 作者:太空宇宙 更新时间:2023-11-04 12:02:56 26 4
gpt4 key购买 nike

我正在处理我们的 32 位 MFC VC2010 应用程序中出现的偶发生产问题。该应用程序在 Windows Server 2008 R2 Standard SP1 64 位上运行。

此问题是由于无法创建 CWnd 派生类引起的。当失败发生时,AfxUnhookWindowCreate 方法在 CWnd::CreateEx 中返回 false。这是因为 pThreadState->m_pWndInit 变量不是 NULL。看起来 _AfxCbtFilterHook 应该在 Hook HCBT_CREATEWND 时将其设置为 NULL,但看起来这并没有发生。我已经注销了 CREATESTRUCT,并将其与失败发生时和未发生时进行比较,并且参数基本相同。

有没有人知道可能导致此问题的原因或我如何确定原因?谢谢!

BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
int x, int y, int nWidth, int nHeight,
HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam)
{
...
if (!PreCreateWindow(cs))
{
PostNcDestroy();
return FALSE;
}

AfxHookWindowCreate(this);
HWND hWnd = ::AfxCtxCreateWindowEx(cs.dwExStyle, cs.lpszClass,
cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,
cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);
...
if (!AfxUnhookWindowCreate())
PostNcDestroy(); // cleanup if CreateWindowEx fails too soon
...

BOOL AFXAPI AfxUnhookWindowCreate()
{
_AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
#ifndef _AFXDLL
if (afxContextIsDLL && pThreadState->m_hHookOldCbtFilter != NULL)
{
::UnhookWindowsHookEx(pThreadState->m_hHookOldCbtFilter);
pThreadState->m_hHookOldCbtFilter = NULL;
}
#endif
if (pThreadState->m_pWndInit != NULL)
{
pThreadState->m_pWndInit = NULL;
return FALSE; // was not successfully hooked
}
return TRUE;
}

LRESULT CALLBACK
_AfxCbtFilterHook(int code, WPARAM wParam, LPARAM lParam)
{
_AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
if (code != HCBT_CREATEWND)
{
// wait for HCBT_CREATEWND just pass others on...
return CallNextHookEx(pThreadState->m_hHookOldCbtFilter, code,
wParam, lParam);
}

...
pThreadState->m_pWndInit = NULL;

最佳答案

我将问题追溯到此时不应该执行的窗口过程 Hook 。

关于c++ - 为什么 CWnd::CreateEx 无法创建我的窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13370578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com