Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


static_cast error with Visual Studio .NET but not with VC6

Posted on 2003-10-31
Medium Priority
Last Modified: 2008-02-01
I use a third party code to implement a plug-in architecture in my application (the code: http://www.codeproject.com/library/piarchitecture.asp).

The code works fine with the compiler of VC6 but when I compile with VS .NET I received a lot of errors C2440 like this one:

static_cast' : cannot convert from 'int (__thiscall CViewInPlugIn::* )(LPCREATESTRUCT)' to 'int (__thiscall CWnd::* )(LPCREATESTRUCT)'
CViewInPlugIn is derived from CPlugInMap and CPlugInMap is derived from CCmdTarget. Maybe the new compiler can't cast a CCmdTarget class to a CWnd class? I know that VS.NET Compiler is more strict with Message Map but I don't know how to resolve or bypass this problem.

Here some parts of my code:

class CViewInPlugIn : public CPlugInMap  
      // ClassWizard generated virtual function overrides
      afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

//Here my implementation

int CViewInPlugIn::OnCreate(LPCREATESTRUCT lpCreateStruct)

      return TRUE ;

and the declaration of CPlugInMap:
class _PLUGIN_API CPlugInMap : public CCmdTarget
      friend class CPlugInApp ;


Question by:Frankbe
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
LVL 48

Accepted Solution

AlexFM earned 2000 total points
ID: 9660628
I reproduced this error compiling the sample application from CodeProject. PlugIn1 project, MFExamplePI.cpp, lines:


The same error message in ON_WM_CREATE line. Solution - add the following lines in the beginning of cpp file:

#define ON_WM_CREATE() \
    { WM_CREATE, 0, 0, 0, AfxSig_is, \
        (AFX_PMSG) (AFX_PMSGW) \
        (reinterpret_cast< int (AFX_MSG_CALL CWnd::*)(LPCREATESTRUCT) > (OnCreate)) },

This is ON_WM_CREATE macro with static_cast replaced by reinterpret_cast. Not so nice, but should work.

Author Comment

ID: 9667051
When you execute the compiled program, do you receive an unhandled exception : access violation reading location 0x00000000?
LVL 48

Expert Comment

ID: 9669246
Actually, I didn't execute it at all. Possibly it contains some bugs, I don't know. If this happens also in VC++ 6, this is not result of ON_WM_CREATE compilation problem.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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