CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Globals

  1. #1
    Join Date
    May 1999
    Posts
    136

    Globals

    Hi,
    I have a modeless dialog which according to the utility Spy++ has no parent. I need to be able to set focus to this dialog across files. What I mean is if I'm in another code file I may need to access this dialog's members. I can't seem to find a way to gain access outside of the file that creates the dialog. Everything is "0".
    Could someone show me how to make a global varialble that has a pointer to the dialog?

    Thanks
    Steve


  2. #2
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Globals

    Put it in your App class so you will have to access it through it.
    For example

    class CMyApp : public CWinApp
    {
    ...
    public:
    CMyDialog * m_MyDialog;
    ...
    };

    Make sure you set it to NULL in the constructor and when it is destroyed. If you do that then now you can do the following in any project file.

    if ( AfxGetApp()->m_MyDialog != NULL )
    {
    // Get my data
    }
    else
    {
    // I don't know maybe create it
    }

    Is this what you are talking about?

    Wayne


  3. #3
    Join Date
    May 1999
    Posts
    136

    Re: Globals

    Wayne,
    does it make a difference if my app is a Dll and another third party app is running and using my dll?

    Steve


  4. #4
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Globals

    If it is a non COM DLL then no it does not matter, because your code is loaded in the same memory space as the exe. If it is a COM Dll, then ?. When I answered your question, I thought it was in a regular EXE. If it is in a DLL then you would not call AfxGetApp(). What I would do is just declare a global pointer to it in the DLL and manipulate it that way. Just make sure you manage it the same way with setting it to NULL if it is not used.

    Wayne


  5. #5
    Join Date
    May 1999
    Posts
    136

    Re: Globals

    Wayne,
    I get a m_MyDialog not a member of CWinApp error.

    Steve


  6. #6
    Join Date
    May 1999
    Posts
    136

    Re: Globals

    Wayne,
    My dll is part of the same memory space. You need to explain how to make a global pointer. I don't understand where to put the declaration or the assignment. Everywhere I've tried the variable isn't seen by my other files.

    Steve


  7. #7
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Globals

    First of all, by your other files, you do mean in the same project, right?

    Let me know,

    Wayne




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured