Create CFrameWnd gives first-chance exceptions--why?

两盒软妹~` 提交于 2021-02-09 11:31:44

问题


I'm attempting to write a simple MFC app that draws in a scrollable window, using code based on CFrameWnd. The code below is adapted from Prosise "Programming Windows with MFC", 2nd ed, pp 89ff.

When I run this in the debugger, I get two first-chance exceptions. If I ignore these, the window appears as expected, and I can draw in it. If I enable break on "C++ exceptions", I get a stack which is only "internal" code, for which I do not have the source. By stepping through the code, I find that the exceptions occur in CWnd::CreateEx, in the call to CreateWindowEx.

What is wrong with this code? 64-bit Windows 7, Visual Studio 2013 update 4. This is a debug build, x64, using MFC in a static library, using multi-byte character set, with the multi-threaded debug runtime (/MTd).

// Viewer.h
#include <afxwin.h>

// Adapted from Prosise "Programming Windows with MFC", 2nd ed, pp 89ff.
class CViewerApp : public CWinApp
{
public:
    virtual BOOL InitInstance();

};

class CMainWindow : public CFrameWnd
{
public:
    CMainWindow();
protected:
    afx_msg void OnPaint();
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnHScroll(UINT nCode, UINT nPos, CScrollBar *pScrollBar);
    afx_msg void OnVScroll(UINT nCode, UINT nPos, CScrollBar *pScrollBar);

public:

    DECLARE_MESSAGE_MAP()
};

// Viewer.cpp: Display
#include <afxwin.h>
#include "Viewer.h"

CViewerApp myApp;

BOOL CViewerApp::InitInstance()
{
    m_pMainWnd = new CMainWindow;
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();

    return TRUE;
}
BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
    ON_WM_CREATE()
    ON_WM_SIZE()
    ON_WM_PAINT()
    ON_WM_HSCROLL()
    ON_WM_VSCROLL()
END_MESSAGE_MAP()

CMainWindow::CMainWindow()
{
    Create(NULL, "Viewer", WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL | WS_MAXIMIZE);
}

int CMainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if(CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    return 0;
}

void CMainWindow::OnPaint()
{
}

void CMainWindow::OnSize(UINT nType, int cx, int cy)
{
    //TO DO
}
void CMainWindow::OnHScroll(UINT nCode, UINT nPos, CScrollBar *pScrollBar)
{
}

void CMainWindow::OnVScroll(UINT nCode, UINT nPos, CScrollBar *pScrollBar)
{
}

回答1:


Thanks to the useful suggestions from @IInspectable and @David Ching, I was able to track down the cause of the problem. It was a piece of software called "Premier Voice", which was installed recently without my knowledge.

I used Process Explorer to trace the usage of pmls64.dll, and Task Manager and autoruns to locate the executables. The program was installed in Programs(x86) in its own folder, and had an uninstall, which I used. I then had to manually delete the folder in Programs(x86), and delete several registry keys.

In addition, this program installed an add-on to Firefox (again without permission), which I had to remove manually.

Besides the exceptions it was causing in my own software, I suspect Premier Voice was what popped up a window today asking me for the date of birth and gender of each user of this computer.



来源:https://stackoverflow.com/questions/28860993/create-cframewnd-gives-first-chance-exceptions-why

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!