Build a Program

I'm now learning Visual C++

Here is my first program:

#include <afxwin.h>

class HelloApp : public CWinApp
      HelloApp ()
            : CWinApp ( "Hello World!" )

      BOOL InitInstance()
            CFrameWnd *MyFrame = new CFrameWnd();
            m_pMainWnd = MyFrame;
            MyFrame->Create ( NULL, (LPCTSTR)"Hello World!" );
            MyFrame->ShowWindow (SW_SHOW );
            return TRUE;
} HelloWorld;

When I try to build a .exe file, it gave me the following message:

--------------------Configuration: Dailup - Win32 Debug--------------------
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
libcd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Dailup.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

Dailup.exe - 4 error(s), 0 warning(s)

what's wrong?
Who is Participating?
Create the project as follows:
1. Select the menu File/New...;
2. Select the Win32 Application project type;
3. Select the menu Project/Add to Project/Files... and select your existing .cpp;
4. Select the menu Project/Settings..., under the General tab, select Use MFC in a Static Library (or Shared DLL) for Microsoft Foundation Classes.
5. Build it.

You just missed out the step 4. nietod was almost there.
It sounds like you aren't linking to the MFC libraries.  But that should take place automatically in an MFC project.  Dod you create the project as an MFC application project?
I think you are making your first windows programm which is usually the "Hello world" program. I think you are not using the AppWizard to create the project. If so, you should make change in your project setting. In link tab, you should change the console to windows in the subsystem option. As of the nafxcwd.lib, you should link the lib with your project if you use some functions in it. Finally, I do not know how you know about C++, if you are learning C++, I suggest you not to use MFC at first. HOpe it helps.
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

gen_genesisAuthor Commented:
I used Win32 Application to create the project.

What should I make change in my project setting
Win32 Application is used for maing a win32 application that doesn't use MFC.  (Or where you manually include the MFC libraries and include files.)   You should create a new project and specify MFC application as the project type.  This creates a win32 application that links with the MFC libraries.
It's O.K. to use Win32 application for this project.
 From development studio Go to Project - Settings - C/C++. Select the Code Generation category. Set the Use run-time library to Debug Multithreaded. Then rebuild. Your .exe will compile without error.
gen_genesisAuthor Commented:
After I changed the setting, it still have error.

--------------------Configuration: Dailup - Win32 Debug--------------------
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Dailup.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

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

I copied your code and created a Win32 app with it and made the change I suggested to you and it works fine. I assure you that this is the correct answer.
May I suggest that you create a new project with WDB's specs and copy the source to this new project. There is obviously some config mismatch between gen_genesis's and wdb's projects.
FOLLOW _WDB_'s instructions and everything will turn out FINE!

Try changing the general settings for MFC from statically linked to shared DLLs. It worked for me.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.