Solved

Global .NET Framework Objects

Posted on 2004-08-18
3
403 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mask Input via OpenSSH 21 104
VC++ 6.0 issue 3 68
vb.net - How to determine string that follows a given substring 7 48
C Language combined operators 28 109
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

785 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