Thread: compiling with vc++.NET

  1. #1
    Unregistered
    Guest

    Angry compiling with vc++.NET

    I've got "Programming Windows with MFC, Second Edition" book, I'm trying to compile its first example with VC++.NET but I'm getting a linker error:

    <ul>
    <li>MFC error LNK2019: unresolved external symbol __endthreadex referenced in function "void __stdcall AfxEndThread(unsigned int,int)" (?AfxEndThread@@YGXIH@Z)</li>
    <li>MFC error LNK2019: unresolved external symbol __beginthreadex referenced in function "public: int __thiscall CWinThread::CreateThread(unsigned long,unsigned int,struct _SECURITY_ATTRIBUTES *)" (?CreateThread@CWinThread@@QAEHKIPAU_SECURITY_ATTR IBUTES@@@Z)</li>
    <li>MFC error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup</li>
    <li>MFC fatal error LNK1120: 3 unresolved externals</li>
    </ul>


    The program source code:

    Code:
    <b>Hello.h</b>
    
    class CMyApp : public CWinApp
    {
    public:
        virtual BOOL InitInstance ();
    };
    
    class CMainWindow : public CFrameWnd
    {
    public:
        CMainWindow ();
    
    protected:
        afx_msg void OnPaint ();
        DECLARE_MESSAGE_MAP ()
    };

    Code:
    <b>Hello.cpp</b>
    
    #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);
    }


    Please help

  2. #2
    Unregistered
    Guest
    Should I add an iclude statement or something?

  3. #3
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    I'm going through the same book now.

    I'm not familiar with MSVC++ .NET (I use MSVC++ 6.0), but I've found that when I get a list of indecipherable error messages, it's usually because I forgot to set the Project Settings to 'Use MFC'

    On MSVC++ 6.0 it's listed under Settings on the Project menu (Alt-F7). On the General tab there's a drop down box entitled Microsoft Foundation Classes. I don't know if there's an equivalent to this with .NET, but it's worth looking at I guess.

    fletch
    "Logic is the art of going wrong with confidence."
    Morris Kline

  4. #4
    Unregistered
    Guest
    Thanks a lot for your response, in fact I have VC++ 6 too, I was trying to compile it using my friend's compiler, because mine gave all kinds of error messages.
    Any way, using VC++ 6, and using your tip, the number of error messages was reduced to 2:

    -------------------Configuration: test - Win32 Debug--------------------
    Compiling...
    Hello.cpp
    Linking...
    msvcrtd.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
    Debug/test.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    test.exe - 2 error(s), 0 warning(s)


    Please help! I've been reading for one week, and I couldn't compile one program till now!

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    The first problem you mentioned has been solved. Indeed those errormessages mean you have to set your project settings to "Use MFC statically/dynamically".

    The second problem is you chose the wrong project type. Copy all your code, open up a new "Win32" Project ( not console ) and paste all your code. This should compile.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Unregistered
    Guest

    Problems solved, thank you guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. vc express compiling???
    By code2d in forum C++ Programming
    Replies: 1
    Last Post: 12-06-2006, 01:14 PM
  3. Difference in MSVC 6 & MS VC .Net
    By passionate_guy in forum C Programming
    Replies: 1
    Last Post: 01-23-2006, 06:39 AM
  4. Porting code from VC++6 to VC .NET??
    By dug in forum C++ Programming
    Replies: 10
    Last Post: 01-31-2005, 11:42 AM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM