Solved

Can't Access Application Class data members.

Posted on 1998-11-25
4
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 216
sumDigits challenge 9 180
maven archtype selection in eclipse 1 59
x-bar in Google Sheets 2 130
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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

710 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