casting errors building VC6 project under VS .NET 7.1

casting errors building VC6 project under VS .NET 7.1

Post by TVR Fa » Wed, 12 May 2004 00:32:39


My application built with no problem under VC++6 but I'm trying to port it
to VC++ .NET in order to use some snazy interface components. Unfortunately,
I'm getting compilation errors building the original code.

I'm running Windows XP and the About MS VC++ box has the following version
information:
MS Development Environmant 2003 - Version 7.1.3088
MS .NET Framework 1.1 - Version 1.1.4322
Installed Products:
Microsoft Visual C++ .NET 69586-335-0000007-18882

I have 3 C2440 errors, all in the AFX_MSG_MAP block. Here's an example.

The error:
error C2440: 'static_cast' : cannot convert from 'void (__thiscall
CBMToolLogView::*)(NMHDR *,LRESULT *)' to 'AFX_PMSG'

In BMToolLogView.h:
// Generated message map functions
protected:
//{{AFX_MSG(CBMToolLogView)
...
afx_msg void OnDblclk(NMHDR* pNMHDR, LRESULT* pResult);
...
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

In BMToolLogView.cpp:
BEGIN_MESSAGE_MAP(CBMToolLogView, CBMToolListView)
//{{AFX_MSG_MAP(CBMToolLogView)
....
ON_COMMAND(IDM_LF_VIEW, OnDblclk) <-- This is where the error is
flagged
....
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

...

void CBMToolLogView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
...
}

As always, any help is hugely appreciated.

--- Al.
 
 
 

casting errors building VC6 project under VS .NET 7.1

Post by Jeff Partc » Wed, 12 May 2004 00:50:24


Unfortunately,
is

That's not the right prototype for an ON_COMMAND handler. MFC7 is much
stricter about message map entries than MFC4 -- which would take pretty much
anything.
--
Jeff Partch [VC++ MVP]

 
 
 

casting errors building VC6 project under VS .NET 7.1

Post by Doug Harri » Wed, 12 May 2004 01:06:34


VC.NET offers better type safety for message map macros, and it caught an
error in your code. You've got two problems:

1. The signature for your OnDlbclk function does not match what ON_COMMAND
expects. The ON_COMMAND macro expects a function such as:

void CBMToolLogView::OnDblclk() {}

But that would break your double-click handler, and it doesn't make sense
for OnDblclk to be in an ON_COMMAND macro. As your class appears to be
derived from CListView, I believe you need:

ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)

2. Apparently you've edited what appears between the AFX comments. Unless
you know what you're doing, you should consider this area off-limits and put
your own stuff outside the comments. It's either that, or the ClassWizard
blew a gasket and messed you up. That said, for a CListView-derived control,
ClassWizard should understand your message, so you can try replacing your
ON_COMMAND entry with the ON_NOTIFY_REFLECT entry above.

P.S. You cross-posted to around 5 groups, most of which aren't relevant to
your question, which fits best into the MFC group. I didn't change this,
because I have no idea which of these groups you're following, and I
wouldn't want you to miss my reply.

--
Doug Harrison
Microsoft MVP - Visual C++
 
 
 

casting errors building VC6 project under VS .NET 7.1

Post by TVR Fa » Wed, 12 May 2004 01:30:55

Thanks, fixed the prototypes and my application now builds and runs. Suppose
I'll have to do lots of testing to make sure it still all works.

I thought I'd have to wait ages for an answer. Much obliged for the quick
response.

--- Al.





it
version
much
 
 
 

casting errors building VC6 project under VS .NET 7.1

Post by TVR Fa » Wed, 12 May 2004 18:22:54

Indeed, this has obviously demonstrated my severe lack of understanding!
Thanks to everyone for their patience with me.

The double click handler was not needed at all and I've completely removed
it. The other handlers that had errors were needed and had essentially the
same problem: incorrect signatures. These are also fixed.

I had, as Doug surmised, edited the stuff within the AFX comments. I
sometimes find it easier to create a new handler by hand, by copying
existing lines in AFX comments and changing the function name. I've
obviously changed more than just the name on occasion and at some point have
completely screwed up with the double click handler. What happens to stuff
within the AFX headers that makes it so important that they not be touched,
and does this mean that I should never create handlers 'by hand'?

Apologies for the cross-posting. I had not expected such an instant response
and thought I'd spread the net wide. I also didn't know for sure that it was
an MFC issue. I hope I'm not getting to much of a reputation around this
forums!

--- Al.



Unfortunately,
is
 
 
 

casting errors building VC6 project under VS .NET 7.1

Post by Scott McPh » Wed, 12 May 2004 21:55:45


The AFX_MSG_MAP headers are used by class wizard to locate and edit the
message maps within the source file. If you *** them up the wizard
gets lost and adding message handlers via the IDE stops working.

You can certainly create handlers by hand, but do it outside of the //{{
.... //}} wizard comments, but inside the
BEGIN_MESSAGE_MAP...END_MESSAGE_MAP macros.


--
Scott McPhillips [VC++ MVP]