Hello World aus Buch funktioniert nicht



  • Ich möchte das Beispiel aus 'Programming Windows with MFC / Jeff Prosise.' erstellen und kompilieren.

    Ein leeres Projekt (in VS 2005 Prof) gefüllt mit einer Klasse hello.cpp/.h
    mit dem Code

    #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);
    }
    
    class CMyApp : public CWinApp
    {
    public:
        virtual BOOL InitInstance ();
    };
    
    class CMainWindow : public CFrameWnd
    {
    public:
        CMainWindow ();
    
    protected:
        afx_msg void OnPaint ();
        DECLARE_MESSAGE_MAP ()
    };
    

    führt nur zu dem Fehler

    libcmt.lib(crt0.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_main" in Funktion "___tmainCRTStartup"

    Im Netz kann ich dazu nur finden das ich versuche ein win32 Projekt als Konsolen Projekt zu kompilieren. Nur dann müsste ja der Quellcode falsch sein oder was ist hier falsch ???

    Matthias



  • du hast ein normales consolen projekt erstellt mit main dein code ist aber keines



  • Und wie erstelle ich dann ein Projekt mit dem ich den dargestellten Code auch kompilieren kann ?

    Ich habe übrigens ein 'leeres' Projekt erstellt.

    Matthias



  • Stelle es in den Linker-Settings um:
    "Project|Properties|Linker|System|SubSystem: Windows"

    Und aktiviere auch, dass Du die MFC verwendest:
    "Project|Properties|General|Use of MFC: Use MFC in a Shared DLL" (oder "Use MFC in a Static Library")


Anmelden zum Antworten