Why won't this work on 2010

I am working through a directx tutorial and the first tutorial's example works perfectly on MS Visual C++ 2008 Express Edition however if I try and use it with MS Visual C++ 2010 Express, it won't work and instead it will only give me this error message:
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\Cameron\documents\visual studio 2010\Projects\t6\Debug\t6.exe : fatal error LNK1120: 1 unresolved externals

Does anyone know why this is? How do I fix this? I did a Google search on this however I came up empty. Thank you very much.


#include <windows.h> // include the basic windows header file

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
// create a "Hello World" message box using MessageBox()
MessageBox(NULL,
L"Hello World!",
L"Just another Hello World program!",
MB_ICONEXCLAMATION | MB_OK);

// return 0 to Windows
return 0;
}
You have to link the project to the used libraries. You must also set your project as a GUI project, not as empty or console.
Last edited on
You created a console project instead of a GUI project and the linker cannot find the entry point.
Ok, thank you for the quick response. How do I link the project to the used libraries?
Also, what is a GUI project and how is it different from a console project?
Finally, why did this work in the old version and not the new version? Thanks
Also, what is a GUI project and how is it different from a console project?


In VS 2010, the project types are called "Win32 Console Application" and "Win32 Application" respectively. The difference is that some linker settings are different (and they start up with different default files). Essentially, the main difference here is the program entry point - a console application will call it main (or _tmain in VS's case, which will either resolve to main or wmain (main that get's a LPWSTR* instead of a LPSTR*)), a Win32 application (confusing term, because a console application can still call win32 functions) will call it WinMain (or _tWinMain, again Microsoft stuff).

You created a console application, so it's looking for _tmain, but it's not there because you only specified WinMain. As the others have already mentioned, the solution is just to create another project with the right settings.

Oh, and it's got nothing to do with the version, the same thing would've happened in VS 2008 too.
Last edited on
Ok, thanks. Now I see my mistake
Topic archived. No new replies allowed.