static_cast error with Visual Studio .NET but not with VC6

I use a third party code to implement a plug-in architecture in my application (the code:

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 ;


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FrankbeAuthor Commented:
When you execute the compiled program, do you receive an unhandled exception : access violation reading location 0x00000000?
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.