简体   繁体   中英

What does creating a Solution using a template in Visual Studio actually do versus an empty project?

I am following the Intro to C tutorial by Molly Rocket but am running into an issue running the following code in the Debugger in VisualStudio 2019 while using the Empty Project option.

I am using the Empty Project option instead of loading a template because that is what Molly used, while I could just load a template and run the code there instead I would like to know why I am getting this error so I can better understand Visual Studio and C++.

#include <Windows.h>

void learnC(void) {

    OutputDebugStringA("Test\n");

}

int CALLBACK WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow) 
{
    learnC();
}

Recieving the error LNK2019 which doesn't help at all because it just a generic catch all error code.

error LNK2019: unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

I have tried updating the compatiliblity settings of VS2019 as well as other settins that people suggested to use but the error still remains.

Again, when I created the Solution I used the blank document instead of a template becuase that is what Molly Rocket used when writing this code.

When I do use a template (I used the Windows Desktop Application template) and delete all the code and paste in what I had in my original document I do not recieve the Error, and I would like to know why.

Thank you for your time!

When you create an Empty Project, the value of SubSystem defaults to Console .

在此处输入图像描述

According to the Doc

An application that uses /SUBSYSTEM:CONSOLE; calls main (or wmain)

An application that uses /SUBSYSTEM:WINDOWS; calls WinMain (or wWinMain), which must be defined to use __stdcall

As far as I'm concerned you should Set up SubSystem to windows ( Properties -> Linker -> System -> SubSystem )

在此处输入图像描述

For more details about /SUBSYSTEM (Specify Subsystem) , I suggest you could refer to the link: https://docs.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=vs-2019

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM