sathvik
1 posts
Help : Visual Studio - Intro to C on Windows
Edited by sathvik on Reason: Initial post
I recently started the Intro to C videos and I am not able to run the following code on Visual Studio 2019 (Version 16.4.5).

As there is no Win32 option in the start menu, I created an empty desktop application using the Windows Desktop Wizard (as in here)

Code:
  1 2 3 4 5 6 7 8 9 10 11 12 13 #include int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ); void foo(void) { } 

Error:
 1 2 3 4 5 6 1>------ Build started: Project: intro_c, Configuration: Debug Win32 ------ 1>Source.cpp 1>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 1>C:\Users\HP\source\repos\intro_c\Debug\intro_c.exe : fatal error LNK1120: 1 unresolved externals 1>Done building project "intro_c.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

Also, if I include
 1  
and write a hello world program along with the above code, the code runs fine.
I searched every error and looked all over the internet, but couldn't find the solution.
What is the problem here ? Have I messed up during creating a new project? Please help.
Mārtiņš Možeiko
2198 posts / 1 project
Help : Visual Studio - Intro to C on Windows
You did not implement the WinMain function. So compiler is asking you to provide implementation.

You need to write code inside WinMain function, like this:
  1 2 3 4 5 6 7 8 9 10 int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { /// .. your code goes here }