C++ 窗口创建失败-LoadFrame(IDR#U大型机)在C++; 我正在将一些Windows应用程序(遗留代码)从VC 6升级到VS2010。大多数应用程序在清除了预期的转换错误后都会编译并运行,但我在这方面遇到了很多问题。这里是LoadFrame()失败和应用程序退出的地方。此处返回的错误为0 CMainFrame* pMainFrame = new CMainFrame;// Create main MDI Frame window if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) DWORD err = GetLastError(); return FALSE;

C++ 窗口创建失败-LoadFrame(IDR#U大型机)在C++; 我正在将一些Windows应用程序(遗留代码)从VC 6升级到VS2010。大多数应用程序在清除了预期的转换错误后都会编译并运行,但我在这方面遇到了很多问题。这里是LoadFrame()失败和应用程序退出的地方。此处返回的错误为0 CMainFrame* pMainFrame = new CMainFrame;// Create main MDI Frame window if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) DWORD err = GetLastError(); return FALSE;,c++,winapi,mfc,porting,visual-c++-6,C++,Winapi,Mfc,Porting,Visual C++ 6,下面是上面的LoadFrame()函数:(pParentWnd和pContext在输入函数时都为Null,我不明白为什么?) 在逐步遍历LoadFrame并检查create方法之后,我发现这里出现了错误:HWND HWND=::AfxCtxCreateWindowEx(..),我注意到cs.hwndParent和cs.hMenu都显示了此错误“unused=cx0030:error:表达式无法计算”。我知道这个错误可能意味着表达式引用的是程序地址空间之外的内存,但我不认为这是问题所在。我在网上看

下面是上面的LoadFrame()函数:(pParentWnd和pContext在输入函数时都为Null,我不明白为什么?)

在逐步遍历LoadFrame并检查create方法之后,我发现这里出现了错误:HWND HWND=::AfxCtxCreateWindowEx(..),我注意到cs.hwndParent和cs.hMenu都显示了此错误“unused=cx0030:error:表达式无法计算”。我知道这个错误可能意味着表达式引用的是程序地址空间之外的内存,但我不认为这是问题所在。我在网上看到过其他类似的问题,但没有任何东西帮助我理解这个问题

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)
{
    ASSERT(lpszClassName == NULL || AfxIsValidString(lpszClassName) || 
        AfxIsValidAtom(lpszClassName));
    ENSURE_ARG(lpszWindowName == NULL || AfxIsValidString(lpszWindowName));

    // allow modification of several common create parameters
    CREATESTRUCT cs;
    cs.dwExStyle = dwExStyle;
    cs.lpszClass = lpszClassName;
    cs.lpszName = lpszWindowName;
    cs.style = dwStyle;
    cs.x = x;
    cs.y = y;
    cs.cx = nWidth;
    cs.cy = nHeight;
    cs.hwndParent = hWndParent;
    cs.hMenu = nIDorHMenu;
    cs.hInstance = AfxGetInstanceHandle();
    cs.lpCreateParams = 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); // RMC here's the error

GetLastError());
DWORD err = GetLastError();

#ifdef _DEBUG
if (hWnd == NULL)
{
    TRACE(traceAppMsg, 0, "Warning: Window creation failed: GetLastError returns 0x%8.8X\n",
        GetLastError());
}

问题源于LoadFrame(),其中父窗口和上下文为Null。为什么它们是“空/??”?(此应用程序在VC 6中运行良好,因此它必须是升级的结果)如果有人看到此问题或有任何信息可以启发我有关此问题,我将不胜感激。提前感谢。

事实证明,我的库路径(链接器->附加依赖项)包含一个支持SDI(单文档接口)而不是MDI(多文档接口)的库。除此之外,MDI库是旧版本(VC6),不支持Visual Studio 2010中使用的新MDI方法。

如果我理解正确,您是说这是失败的内部MFC库代码。真奇怪。我的第一个想法是你的环境有严重问题。您可以创建和构建一个新的应用程序而不迁移任何内容吗?不久前,我遇到了类似的问题,当我的打印预览在将应用程序从VC6升级到VS2010后无法工作,它将崩溃。我发现MFC打印预览的内部已更改,导致崩溃。我记得我必须驾驶自己的打印预览窗口来解决这个问题,我为此感到非常自豪。因此,我建议将VS2010的MFC
框架
功能与VC6的MFC
功能进行比较,注意发生了哪些变化,并进行相应的计划。查看
CMainFrame::OnCreate()
,查看是否有任何子组件未能创建并返回-1。@CodyGray是,它似乎是内部MFC。这也是我的想法,但是我可以毫无问题地创建和构建一个新的应用程序吗?这个程序依赖于.dll,这会对窗口的创建产生影响吗?是SDI还是MDI?您还应该注意,在VS2010中,每个MDI都会在一个新窗口中打开,而不是在VC6中打开MDI。
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)
{
    ASSERT(lpszClassName == NULL || AfxIsValidString(lpszClassName) || 
        AfxIsValidAtom(lpszClassName));
    ENSURE_ARG(lpszWindowName == NULL || AfxIsValidString(lpszWindowName));

    // allow modification of several common create parameters
    CREATESTRUCT cs;
    cs.dwExStyle = dwExStyle;
    cs.lpszClass = lpszClassName;
    cs.lpszName = lpszWindowName;
    cs.style = dwStyle;
    cs.x = x;
    cs.y = y;
    cs.cx = nWidth;
    cs.cy = nHeight;
    cs.hwndParent = hWndParent;
    cs.hMenu = nIDorHMenu;
    cs.hInstance = AfxGetInstanceHandle();
    cs.lpCreateParams = 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); // RMC here's the error

GetLastError());
DWORD err = GetLastError();

#ifdef _DEBUG
if (hWnd == NULL)
{
    TRACE(traceAppMsg, 0, "Warning: Window creation failed: GetLastError returns 0x%8.8X\n",
        GetLastError());
}