|
-
March 31st, 1999, 04:21 PM
#1
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!
-
March 31st, 1999, 07:12 PM
#2
Re: Global application object
:-)
Try to use :
extern CString s;
in other file
-
March 31st, 1999, 07:40 PM
#3
Re: Global application object
One way is to use an extern declaration like this
class CMDIApp ublic CWinApp
{//...}
extern CMDIApp theApp;
-
March 31st, 1999, 09:02 PM
#4
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
-
April 1st, 1999, 06:01 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|