Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 1998-01-14
4
Medium Priority
?
382 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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…
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.

886 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