VC++ Error C2642

Posted on 1997-05-02
Last Modified: 2010-04-10
I'm using MSVC++ V1.52
Trying to set up a simple 1 sec timer.

On the line "ON_WM_TIMER()", which the tool inserted,
I get the following compile error:

"error C2642: cast to pointer to member must be from related pointer to member"

This works OK in another class, but not this one.

Question by:mrkerry
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

Expert Comment

ID: 1163221
Are you sure that your class delivered from CWnd class?
LVL 10

Expert Comment

ID: 1163222
Please post the source code that was generated (header and cpp).

Post as a comment to here and/or direct to me at

Accepted Solution

TKII earned 100 total points
ID: 1163223
I believe you are trying to use a timer in a class not derived from CWnd. Such a class is for instance CDocument. You should use the associated view-class for your timer or the MainFrame CMainFrame. You should use the classwizzard to add the generic handler and message-map-entries for the WM_TIMER-message.

Author Comment

ID: 1163224
Thanks...your answer was right on. I don't know how to grade but you get an A.

Expert Comment

ID: 1163225
Thanks, your welcome.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert MFC APP to Win32 APP. 19 111
Printing the elements of a set declared inside a map in C++. 3 58
Best book to learn C++ 4 87
designing in object programming 12 105
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…

756 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