如何在C ++中访问新的Main Function的参数? [英] How do I access arguments for a new Main Function in C++?
问题描述
我有一个新的主要功能,要求链接程序在Visual Studio中指向它.
I have a new main function that I asked the linker to point to in the Visual Studio.
我可以正确执行此功能.但是,我得到的命令行参数不正确.
I can correctly execute this function. However the command line arguments that I am getting is not correct.
当前这是我的签名
int NewMain(int argc, const char* argv[])
{
cout << "New Main" << endl;
for (int i = 0; i < argc; ++i)
{
cout << argv[i] << "\n";
}
return 0;
}
但是,当我将相同的函数与标准main一起使用时,我会得到所有参数.
However when I use the same function with the standard main, I am getting all the arguments.
推荐答案
当您指定链接器的入口点时,调用的函数不会传递 any 参数.它的签名是int entrypoint(void);
When you specify an entry point to the linker, the function that gets called is not passed any arguments. Its signature is int entrypoint(void);
如果需要命令行,可以使用GetCommandLine
进行检索.如果要将其解析为参数,则可以自己进行解析,也可以使用CommandLineToArgvW
,但请注意,宽字符版本仅提供 功能,因此如果需要标准命令行(使用char
,而不是wchar_t
),您必须自己执行此操作.
If you want the command line, you can retrieve it with GetCommandLine
. If you want to parse that into arguments, you can either do so on your own, or use CommandLineToArgvW
-- but note that this is only available in a wide-character version, so if you want a standard command line (using char
s, not wchar_t
s) you have to do that on your own.
这篇关于如何在C ++中访问新的Main Function的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!