Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refering to App variable from Dialog

Status
Not open for further replies.

skwrox

Programmer
Oct 9, 2001
4
US
I need to refer to, and set an Application variable from my Dialog class. I tried this:

CMyAppApp * pApp = AfxGetApp();

The error says it needs reinterpret_cast, C-style cast or function-style cast. So I tried:

CMyAppApp * pApp = dynamic_cast<CMyAppApp *>(AfxGetApp());

I still get a warning saying 'dynamic_cast' used on polymorphic type 'class CWinApp' with /GR-; unpredictable behavior may result. The app. crashes at that line.

What's wrong? How else can I refer to an App. class variable? Someone please explain?

TIA
Sudhir
 
Hi, you have 2 ways how to solve it...

CMyAppApp * pApp = AfxGetApp();
1. use different type casting
- C style: CMyAppApp* pApp = ( CMyAppApp * ) AfxGetApp();
- reinterpret_cast
- static_cast

CMyAppApp * pApp = dynamic_cast<CMyAppApp *>(AfxGetApp());
2. enable Run-Time Type Information( RTTI ) either by setting compiler option /GR or Dev. Studio you can change project settings: C/C++ : C++ Language : Enable...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top