error C2440: 'static_cast' : cannot convert from ...

N

Neo

Greetings!

I'm upgrading a VC6 project to VC7.1 (Visual Studio .NET 2003). It is a MFC
project with Doc/View architecture. There is a user-defined message to
handle. Here is the code:
====================================================================
// MainFrm.h
class CMainFrame : public CMDIFrameWnd
{
...
afx_msg void OnParse(UINT wParam, LONG lParam);
...
}

// MainFrm.cpp
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
...
ON_THREAD_MESSAGE(WM_PARSER_THREAD_CALL, OnParse)
...
END_MESSAGE_MAP()

void CMainFrame::OnParse(UINT wParam, LONG lParam)
{
CDocument *pDoc = (CDocument *)theApp.GetDocument();

ASSERT_VALID(pDoc);

if(pDoc && pDoc->IsKindOf(RUNTIME_CLASS(CDocument)))
{
// Frame receives the message, but document does the work
pDoc->OnParse(wParam, lParam);
}
}

// MyProgram.h
#define WM_PARSER_THREAD_CALL WM_USER+1

// MyProgram.cpp
UINT ParserThread(LPVOID pParam)
{
...
SendMessage(hWndMain, WM_PARSER_THREAD_CALL, 0, 0);
...
}
======================================================================
When I compiled the program, I got the following error:

error C2440: 'static_cast' : cannot convert from 'void (__thiscall
CMainFrame::* )(UINT,LONG)' to 'void (__thiscall
CWinThread::* )(WPARAM,LPARAM)'

I tried to move my message handler to "CWinApp" and built it successfully,
but it doesn't work. Could anyone please give me some advice on how to
correct this? Thanks a lot!

Neo
 
F

Feng Yuan [MSFT]

The error message is very clear.

Use OnParse(WPARAM wParam, LPARAM lParam)

The new header files have been changed to 64-bit compiler compatible. So you
can't assume pointers are always 32-bit. As pointers can be passed through
LPARAM, it's not the same as LONG anymore.

Make your program 64-bit ready. It's coming soon to normal people.
 
B

Bjarne Nielsen

Feng Yuan said:
The error message is very clear.

Use OnParse(WPARAM wParam, LPARAM lParam)

The new header files have been changed to 64-bit compiler compatible. So you
can't assume pointers are always 32-bit. As pointers can be passed through
LPARAM, it's not the same as LONG anymore.

Make your program 64-bit ready. It's coming soon to normal people.

A couple of other things:
The prototype must be
LRESULT OnParse(WPARAM wParam, LPARAM lParam);
not

void OnParse(WPARAM wParam, LPARAM lParam);

Besides, don't use WM_USER based messages. Use WM_APP + x or even better
call RegisterWindowMessage(), in which case the message map must be:
ON_REGISTERED_THREAD_MESSAGE(WM_PARSER_THREAD_CALL, OnParse)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top