Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 249
Safe conversion? 4 72
Android development question 2 55
How to convert Structure to vector of byte and vice versa 5 25
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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

821 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