Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

729 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