Solved

static_cast error with Visual Studio .NET but not with VC6

Posted on 2003-10-31
3
568 Views
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_VIRTUAL(CViewInPlugIn)
      afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
      //}}AFX_VIRTUAL
................
};


//Here my implementation
BEGIN_MESSAGE_MAP(CViewInPlugIn, CPlugInMap)
      //{{AFX_MSG_MAP(CViewInPlugIn)
      ON_WM_CREATE()
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

int CViewInPlugIn::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      ...............

      return TRUE ;
}

and the declaration of CPlugInMap:
class _PLUGIN_API CPlugInMap : public CCmdTarget
{
      friend class CPlugInApp ;
      DECLARE_DYNCREATE(CPlugInMap)

......................

      DECLARE_MESSAGE_MAP()
};
0
Comment
Question by:Frankbe
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
Comment Utility
I reproduced this error compiling the sample application from CodeProject. PlugIn1 project, MFExamplePI.cpp, lines:

BEGIN_MESSAGE_MAP(CMFPI, CPlugInMap)
    //{{AFX_MSG_MAP(CMFPI)
    ON_WM_CREATE()
    ON_COMMAND(ID_VIEW_MYNEWTOOLBAR, OnViewMyNewToolbar)
    ON_UPDATE_COMMAND_UI(ID_VIEW_MYNEWTOOLBAR, OnUpdateViewMyNewToolbar)
    ON_COMMAND(ID_FILE_SOMENEWOPTION, OnSomeNewOption)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

#undef ON_WM_CREATE
#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.
0
 

Author Comment

by:Frankbe
Comment Utility
When you execute the compiled program, do you receive an unhandled exception : access violation reading location 0x00000000?
0
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now