Solved

->((CMainFrame*): syntax error : '(' ; why?

Posted on 1998-01-14
4
348 Views
Last Modified: 2010-04-10
I have some errors that I cannot resolve. I'm using VC++ 4.0, DirectX 3.0.

This line:

AfxGetApp()->m_pMainWnd->m_pDirectDraw->GetDisplayMode(&ddsdDesc);

Gives the following error:

Compiling...
MainFrm.cpp
C:\Vc++\Projects\Asteroid\MainFrm.cpp(579) : error C2039: 'm_pDirectDraw' : is not a member of 'CWnd'

m_pDirectDraw, true enough, is not a member of CWnd. It's a member of class CMainFrame (: public CFrameWnd). That's why I need to cast it to CMainFrame, right? So, I tried:

AfxGetApp()->((CMainFrame*)m_pMainWnd)->m_pDirectDraw->GetDisplayMode(&ddsdDesc);

And received this:

Compiling...
MainFrm.cpp
C:\Vc++\Projects\Asteroid\MainFrm.cpp(579) : error C2059: syntax error : '('

What's wrong with a "(" there? I have to cast it. To cast something, you need to enclose the new type in (), right?

How do I fix this?
0
Comment
Question by:TylerRick
[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
4 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1178315
Try
     (CMainFrame*)(AfxGetApp()->m_pMainWnd)->m_pDirectDraw->GetDisplayMode
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 50 total points
ID: 1178316
More correctly, you should use MFC's runtime type info:

  CMainFrame* frame = NULL;
  if (AfxGetApp()->m_pMainWnd->IsKindOf(RUNTIME_CLASS(CMainFrame)))
  {
    frame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
    frame->m_pDirectDraw->GetDisplayMode(&ddsdDesc);
  }
  else
  {
    TRACE("Pointer is not the right type!\r\n");
  }

0
 

Author Comment

by:TylerRick
ID: 1178317
Thanks! Both of your suggestions worked.

To nietod:

I had to change your example to:
((CMainFrame*)(AfxGetApp()->m_pMainWnd))->m_pDirectDraw->GetDisplayMode(&ddsdDesc);
0
 

Author Comment

by:TylerRick
ID: 1178318
Thanks! Both of your suggestions worked.

To nietod:

I had to change your example to:

((CMainFrame*)(AfxGetApp()->m_pMainWnd))->m_pDirectDraw->GetDisplayMode(&ddsdDesc);

before it compiled, though.
0

Featured Post

Industry Leaders: 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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

732 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