Winforms 将命令行参数传递到C++/CLI

Winforms 将命令行参数传递到C++/CLI,winforms,c++-cli,Winforms,C++ Cli,我已经学习C++/CLI几个月了,但无论我尝试什么,我似乎都无法解决我遇到的问题 我需要将字符串^、数组^或ArrayList^数据类型从main.cpp传递到Form1.h。我尝试在main.cpp中将变量设置为全局变量,然后使用extern调用该变量。但是,这不适用于字符串、数组和ArrayList数据类型 我该怎么做呢?提前谢谢。下面是我的代码的一个解释: //main.cpp bool LoadFileFromArgument = false; //A boolean can be d

我已经学习C++/CLI几个月了,但无论我尝试什么,我似乎都无法解决我遇到的问题

我需要将字符串^、数组^或ArrayList^数据类型从main.cpp传递到Form1.h。我尝试在main.cpp中将变量设置为全局变量,然后使用extern调用该变量。但是,这不适用于字符串、数组和ArrayList数据类型

我该怎么做呢?提前谢谢。下面是我的代码的一个解释:

//main.cpp

bool LoadFileFromArgument = false; //A boolean can be declared global
String^ argument; //this will not pass from main.cpp to Form1.h

int main(array<System::String ^> ^args)
{
String ^ argument = args[1]

// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false); 

// Create the main window and run it
Application::Run(gcnew Form1());

return 0;
}



//Form1.h

public ref class Form1 : public System::Windows::Forms::Form
{
public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //

        extern bool LoadFileFromArgument; //is grabbed without error
        extern String^ argument; //will not work

不能为窗体创建重载构造函数。i、 e

public ref class Form1 : public System::Windows::Forms::Form
{
public:
    Form1(String^ argument)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        // 
        // Use "argument" parameter as req'd.
    }

    Form1(void)
    {
        //....usual constructor here...
        //..etc...
然后从主要

// Create the main window and run it
Application::Run(gcnew Form1(argument));

谢谢你,格姆,我以前试过,但从来没有成功过。非常简单,谢谢!如何检测参数是否为空?因为它将导致越界错误
// Create the main window and run it
Application::Run(gcnew Form1(argument));