Solved

Global .NET Framework Objects

Posted on 2004-08-18
3
402 Views
Last Modified: 2010-04-24
I just started playing around with the .NET VC++. I'm trying to make a string, or a pointer to a File object, global throughout a form. Whenever I try to do either, I get an error that says .NET Framework objects cannot be global. What I have is one button asks the user for the filename, and a completly different part of the code writes to that file, so I need a way to pass either the file name or a reference to a File object between the two. The button never calls the other function directly, as the other function is on a timer that runs at regular intervals, so I can't just pass the filename. Thanks.
0
Comment
Question by:jasoncout
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 11830206
Keep .NET class instance as class member:

class SomeClass
{
    ...
    String* someString;
};

If you need to make it global (the only instance in the program), use static class member.
0
 

Author Comment

by:jasoncout
ID: 11830297
I get the same error when it is in a class. This is the exact error:

Form1.h(26): error C3145: 'captureFileName' : cannot declare a global or static managed type object or a __gc pointer

and the code:


namespace D2XX_GUI
{
      using namespace System;
      using namespace System::ComponentModel;
      using namespace System::Collections;
      using namespace System::Windows::Forms;
      using namespace System::Data;
      using namespace System::Drawing;

      static System::String *captureFileName;
               .
               .
               .



0
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 11830435
I don't see that captureFileName belongs to the class.

namespace D2XX_GUI
{
     using namespace System;
     using namespace System::ComponentModel;
     using namespace System::Collections;
     using namespace System::Windows::Forms;
     using namespace System::Data;
     using namespace System::Drawing;

    __gc  class SomeClass
    {


         static System::String *captureFileName;
     }


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB Email Check 2 247
How do I send a SOAP request to an endpoint via Microsoft VS C++? 1 73
L prefix in C++ 8 103
bullzip printer only saves PDF in black and white. 5 86
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now