Solved

Can't Access Application Class data members.

Posted on 1998-11-25
4
160 Views
Last Modified: 2013-11-20
Hi,
I have and SDI application. I have declared few public
variables to the Application Class as well as MainFrame class.

How do I access these variables from a new class created
by me? When I used AfxMainWnd()-> or AfxGetApp()->
it gave the following errors respectively.
error C2039: 'EntityFileName' : is not a member of 'CWnd'
error C2039: 'EntityFileName' : is not a member of 'CWinApp'

I had declared 'EntityFileName' as a Cstring in the respective classes. Is it that only base class members are
accessed using those functions?

What is the solution???
Thanks.
 
0
Comment
Question by:leena_mary
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 50 total points
ID: 1325270
You see, ::AfxGetApp() returns a pointer to CWinApp class and not your own application class, which, let us say is called CMyApp
To get over this problem, you do the following:

CMyApp *m_pApp;
m_pApp=(CMyApp *)::AfxGetApp();
// access your variable now like m_pApp->EntityFileName
For the variable in the MainFrame class you could do something like this:
CMainFrame *m_pFrWnd=::AfxGetApp()->m_pMainWnd;
//and then m_pFrWnd->EntityFileName

Hope this will sort your problem.
Thanks and best of luck.
pagladasu


0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1325271
Hi,
Just an afterthought. You can interact with all the classes in a Document-View application architecture.
The important thing is that most funtions will return a pointer to the base class. Since with a pointer to the base class, you can only access the base class members even if you make it point to a derived class object. The only way it helps is in implementing run time polymorphism. If you want this pointer to access derived class members also, you must do an exclusive type-casting.
Hope this will clear up your doubts. Any other queries, feel free to clarify them. My email address is:
espical@hotmail.com
Thanks.
pagladasu.
0
 

Author Comment

by:leena_mary
ID: 1325272
Thanks, pagladasu.

0
 

Author Comment

by:leena_mary
ID: 1325273
Thanks, pagladasu.

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 21
Detect CR LF to each line 12 137
sameEnds challenge 3 106
MaxSpan challenge 9 67
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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, fr…

706 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

20 Experts available now in Live!

Get 1:1 Help Now