Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entry point for MFC application

I have created new emty project. Then have added cpp and header hello world files taken from Jeff Prosise 'Programming Windows with MFC' book. Have set Use of MFC to Use MFC in a Shared DLL

Got error entry point must be defined How to fix this problem?

CPP:

#include <afxwin.h>
#include "Hello.h"

CMyApp myApp;

/////////////////////////////////////////////////////////////////////////
// CMyApp member functions

BOOL CMyApp::InitInstance ()
{
    m_pMainWnd = new CMainWindow;


   m_pMainWnd->ShowWindow (m_nCmdShow);
    m_pMainWnd->UpdateWindow ();
    return TRUE;
}

/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions

BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
    ON_WM_PAINT ()
END_MESSAGE_MAP ()

CMainWindow::CMainWindow ()
{
    Create (NULL, _T ("The Hello Application"));
}

void CMainWindow::OnPaint ()
{
    CPaintDC dc (this);

    CRect rect;
    GetClientRect (&rect);

    dc.DrawText (_T ("Hello, MFC"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}

H:

class CMyApp : public CWinApp
{
public:
    virtual BOOL InitInstance ();
};

class CMainWindow : public CFrameWnd
{
public:
    CMainWindow ();

protected:
    afx_msg void OnPaint ();
    DECLARE_MESSAGE_MAP ()
};
like image 332
vico Avatar asked Apr 07 '14 10:04

vico


1 Answers

You need to tell compiler to use WinMain (which is provided by MFC: http://msdn.microsoft.com/en-us/library/akdx0603.aspx) instead of main as an entry point.

Right click project, select Properties, and navigate to Linker -> System -> SubSystem. Change SubSystem to Windows.

like image 62
Nemanja Boric Avatar answered Sep 30 '22 13:09

Nemanja Boric