title: Passing command line arguments to a windows form file in C++/CLI
body: <p>I've been learning C++/CLI for a few months now, but no matter what I try, I can't seem to fix a problem I'm having.</p>
  
  <p>I need to pass either a String^, Array^, or an ArrayList^ data type from main.cpp to Form1.h. I've attempted to make variables global in main.cpp and then call the variable using extern. However, this will not work for String, Array, and ArrayList data types.</p>
  
  <p>How would I go about doing this? Thanks in advance. Here is a paraphrase of my code:</p>
  
  <pre><code>//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&lt;System::String ^&gt; ^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
  </code></pre>
  
  <p>Here is the error:</p>
  
  <pre><code>error C3145: 'argument' : global or static variable may not 
  have managed type 'System::String ^'
  
  may not declare a global or static variable,
  or a member of a native type that refers to objects in the gc heap
  </code></pre>