Pregunta

I'm in the middle of upgrading some windows applications (Legacy Code) from VC 6 to VS2010. Most of the applications compiled and would run after cleaning up expected conversion errors, but I'm having a lot of trouble with this. Here is where LoadFrame() fails and the application exits. The error returned here is 0.

     CMainFrame* pMainFrame = new CMainFrame;// Create main MDI Frame window
     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
         DWORD err = GetLastError();
     return FALSE;

Here is the LoadFrame() function from above:(pParentWnd and pContext are both Null on entering the function and I don't understand why?)

BOOL CMDIFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
CWnd* pParentWnd, CCreateContext* pContext)
{
    if (!CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle,
      pParentWnd, pContext))
        return FALSE;

    // save menu to use when no active MDI child window is present
    ASSERT(m_hWnd != NULL);
    m_hMenuDefault = ::GetMenu(m_hWnd);
    return TRUE;
}

After stepping through the LoadFrame and examining the create methods, I discovered that this is where the error occurs here: HWND hWnd = ::AfxCtxCreateWindowEx(..) I noted that cs.hwndParent and cs.hMenu are both showing this error "unused = CXX0030: Error: expression cannot be evaluated". I know that this error can mean that the expression is referring to memory outside the programs address space, but I don't see this being the issue.I have seen other issues online which are similar to this, but nothing has helped me understand the problem.

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

The problem is stemming from the LoadFrame() where the Parent Window and Context are Null. Why are they "null/???"? (This application runs fine in VC 6, so it has to be a result of the upgrade) If someone has seen this issue or has any information that may enlighten me about the problem, I would be extremely grateful. Thanks in Advance.

¿Fue útil?

Solución

It turns out that my library path (Linker -> Additional Dependencies) contained a library which supported SDI(Single-Document Interface) opposed to MDI(Multiple-Document Interface). As well as that, the library for MDI was an older version (VC6) which did not support the new MDI methods that are used in Visual Studio 2010.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top