Solved

static_cast error with Visual Studio .NET but not with VC6

Posted on 2003-10-31
3
590 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
[X]
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
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 9660628
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
ID: 9667051
When you execute the compiled program, do you receive an unhandled exception : access violation reading location 0x00000000?
0
 
LVL 48

Expert Comment

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

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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