Solved

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

Posted on 1998-01-14
4
336 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
  • 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

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

18 Experts available now in Live!

Get 1:1 Help Now