Visual Studio C++ warning C4829: Possibly incorrect parameters to function main.

It has been a very long time since I wrote C++. I have the latest VS 2022 community installed. When I do my build, I get the warning "warning C4829: Possibly incorrect parameters to function main. Consider 'int main(Platform::Array<Platform::String^>^ argv)'"

This is the main function definition.

void main(array<String^>^ args) {

When I try to replace the arguments with the suggestion it will generate a bunch of errors. I don't see Platform in the intellisence, which I think is causing the cascade of errors so I'm a little confused.
Last edited on
main's parameters in C++ are as follows, you can't change them.

int main()
int main(int argc, char *argv[])

Occasionally you might see int main(int argc, char **argv), its just a different way to do a 2D C string array.

The names argc and argv are traditional, but you can name them whatever you like.

In C++ main returns int, it is never void.

In C++ main

Can't be overloaded.
Can't be declared as inline.
Can't be declared as static.
Can't have its address taken.
Can't be called from your program.

Last edited on
It seems like Visual Studio's default settings are trying to encourage you use C++/CLI, which is Microsoft's extension of the C++ language to work with ".NET".

If you don't know what that means, then you probably don't need it, and should just focus on standard C++:

(1) Create a new project --> Language: C++ --> Empty Project, "Start from scratch with C++ for Windows. Provides no starting files." Not "CLR Empty Project (.NET Framework)".
(2) Right-click project after it loads --> Add --> New Item... --> C++ File (.cpp) --> name it --> Add
(3) Write code
#include <iostream>

int main()
    std::cout << "Hello, world!\n";
Thanks for the responses. Like I said it has been a long time since I used VS. I would normally use argc & argv, but since they implemented this management of objects and such in the 2022 version it threw me for a loop. I will spend time learning this new version and see if I can get back to using it again quickly.

@Ganado - I did the create an empty project and it does compile successfully. I do need to use Forms so I changed it to a Windows project by setting the Properties -> Linker -> System -> SubSystem to Windows. But I still don't see the form object. Is there something else I need to set to include that?
Last edited on
Topic archived. No new replies allowed.