CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 1999
    Posts
    2

    Global application object



    I want to retrieve my own implemented variables in the CWinApp-derived class from another class (The variables hold values from an INI-file).


    How do I refer to the one and only global application object from another implemented class ( i.e CString s=theApp.myvariable )???


    Please help me!



  2. #2
    Join Date
    Mar 1999
    Posts
    3

    Re: Global application object



    :-)

    Try to use :


    extern CString s;


    in other file

  3. #3
    Join Date
    Apr 1999
    Posts
    16

    Re: Global application object



    One way is to use an extern declaration like this

    class CMDIApp ublic CWinApp

    {//...}

    extern CMDIApp theApp;

  4. #4
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Global application object



    1) if you only want to read them once, the place is InitInstance

    2) Create a static class, holding only static members and static functions

    3) In InitInstance read from INI file and poke the values into the static class

    4) Access the values from this static class whereevere you need them

    5) Lycka till


    Sally




  5. #5
    Join Date
    Apr 1999
    Posts
    383

    Re: Global application object



    Use AfxGetApp(), which returns a pointer to the application object, and cast it to your derived class like this:


    CMyApp* pMyApp = dynamic_cast (AfxGetApp());


    Now you can access your derived application public members:


    int value = pMyApp->GetValue();


    Dave

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