3

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)
{
}
Woody20
  • 791
  • 11
  • 30
  • This is likely an effect caused by an application running in your desktop, that installs a global hook or causes code to run in your process using other infrastructure. Inside the handler an exception is raised, and later caught (otherwise you'd see a second-chance exception, together with an *uncaught exception* dialog). To solve this you'd have to identify the faulting application, and remove it from your system. Other than that, there's nothing wrong with your code. Reading Prosise is the right way to learn MFC. – IInspectable Mar 04 '15 at 18:21
  • What are the exceptions that are thrown? As IInspectable says, it could be caused by some type of code injection into your process; if so, you would be able to see that DLL on the call stack. – David Ching Mar 04 '15 at 19:23
  • The information in the output window is "First-chance exception at 0x000007FEFD4B940D in MainWindowTest.exe: Microsoft C++ exception: Win32Util::Error at memory location 0x00000000025EF130." There are two identical lines like this. – Woody20 Mar 04 '15 at 20:54
  • IInspectable - Any suggestions for how to identify the faulting application? Sysinternals autoruns shows hundreds of startups, and I'm not sure terminating processes with Task Manager would remove the cause of the error. – Woody20 Mar 04 '15 at 21:08
  • This is the stack at the time of the first-chance exception (break on C++ exceptions enabled): KernelBase.dll!000007fefd4b940d() Unknown pmls64.dll!000000018007b7e6() Unknown pmls64.dll!00000001800095b5() Unknown pmls64.dll!000000018005af82() Unknown pmls64.dll!000000018005f2c7() Unknown pmls64.dll!000000018005fa11() Unknown pmls64.dll!000000018007db7f() Unknown pmls64.dll!000000018007dc33() Unknown [External Code] – Woody20 Mar 04 '15 at 22:57
  • The application can be identified by looking at the callstack of the faulting thread inside Visual Studio. Among other information it shows the module containing the code (*pmls64.dll*). Switching to the *Module* window (*Debug* -> *Windows* -> *Modules*) and looking for that module displays the *Path*. From there it should be trivial to figure out which application the module belongs to. – IInspectable Mar 05 '15 at 19:47

1 Answers1

0

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.

Woody20
  • 791
  • 11
  • 30