M
M
mardari982020-02-18 21:54:30
C++ / C#
mardari98, 2020-02-18 21:54:30

Why doesn't the code compile in Visual Studio 2019?

Trying to compile this code (from the book):

spoiler
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 LPSTR lpCmdLine, int nCmdShow)
{
 MessageBox(NULL, "Hello, Win32 world!", "Hello from Message Box", MB_OK);
 return 0;
}

In devc++ it compiles without issue, but in Visual Studio there are errors:
spoiler
5e4c32de8aaea983723768.png


Why is this happening and how to solve the problem?

UPD: As far as I understand, the problem is that there is no main function (but why is this not a problem in devc ++, and there is not a word about any main in the book).
Did it like this:
int main() {
    WinMain(0,0,0,0);
    return 0;
}

Randomly poked zeros instead of arguments, I don’t know if I did the right thing. But it compiled. Chinese letters instead of Latin. Changed "Hello, Win32 world!" to (LPWSTR)L"Hello, Win32 world!".

And everything seems to work as it should, but is it all right? Why is everything OK in one environment, and there is no need to create crutches, but in the "best IDE" on the planet such a disaster?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
menkar3, 2020-02-18
@mardari98

Because the application entry point is set in the studio project settings, and you, as I understand it, created the default one =)
The first link in Google: https://stackoverflow.com/questions/18067870/what-...
Of. documentation - https://docs.microsoft.com/en-us/cpp/build/referen...
In short:
5e4c3eb70af5d542955543.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question