Click to See Complete Forum and Search --> : Buod Error 2440


spynet
July 19th, 2005, 09:44 AM
Hi,
I have the follow error while I compile a program from visual c++(visual studio 6.0) to visual studio .net..

This is the code where I have the error:

In the header file:

afx_msg BOOL OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct);


in the .cpp file

ON_MESSAGE(WM_COPYDATA, OnCopyData)
(Here this is the point of error)...


This is the body of function:

//-----------------------------------------------------------------------------
BOOL CPwSafeDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
DWORD dwLen, dwPasswordLen, dwKeyFileLen;
CString strData, strPassword, strKeyFile, strFile;

NotifyUserActivity();

if(pCopyDataStruct->lpData != NULL)
{
dwLen = (DWORD)_tcslen((LPCTSTR)pCopyDataStruct->lpData);
if(dwLen == 0) return TRUE;

strData = (LPCTSTR)pCopyDataStruct->lpData;
dwPasswordLen = pCopyDataStruct->dwData >> 16;
dwKeyFileLen = pCopyDataStruct->dwData & 0xffff;

if((dwPasswordLen + dwKeyFileLen) >= dwLen) return TRUE;

if(dwPasswordLen != 0) strPassword = strData.Mid(0, dwPasswordLen);
if(dwKeyFileLen != 0) strKeyFile = strData.Mid(dwPasswordLen, dwKeyFileLen);

if((dwPasswordLen + dwKeyFileLen) != 0)
strFile = strData.Right(strData.GetLength() - (int)dwPasswordLen - (int)dwKeyFileLen);
else strFile = strData;

if(strFile.GetLength() == 0) return TRUE;

OnFileClose();
if(m_bFileOpen == TRUE) return TRUE;

if((dwPasswordLen != 0) && (dwKeyFileLen != 0))
_OpenDatabase(strFile, strPassword, strKeyFile, FALSE, NULL);
else if(dwPasswordLen != 0)
_OpenDatabase(strFile, strPassword, NULL, FALSE, NULL);
else if(dwKeyFileLen != 0)
_OpenDatabase(strFile, NULL, strKeyFile, FALSE, NULL);
else
_OpenDatabase(strFile, NULL, NULL, FALSE, NULL);

if((m_bMinimized == TRUE) || (m_bShowWindow == FALSE)) OnViewHide();
}

return TRUE;

}
/----------------------------------------------




The error message is:
error C2440: "static_cast": impossibile convertire da "BOOL (__thiscall CPwSafeDlg::* )(CWnd *,COPYDATASTRUCT *)" a "LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)"..

Can anyone able to help me, please?

Thank you very much..

philkr
July 19th, 2005, 09:57 AM
Your message handling function must have the parameter format (WPARAM, LPARAM). You can then cast the LPARAM to a COPYDATASTRUCT* in the function.

spynet
July 19th, 2005, 10:01 AM
Sorry,
Can you show me an example?

Thank you for your reply.

philkr
July 19th, 2005, 10:04 AM
afx_msg LRESULT OnCopyData(WPARAM wParam, LPARAM lParam);
ON_MESSAGE(WM_COPYDATA, OnCopyData)

LRESULT CPwSafeDlg::OnCopyData(WPARAM wParam, LPARAM lParam)
{
COPYDATASTRUCT* pCopyDataStruct = (COPYDATASTRUCT*)lParam;
DWORD dwLen, dwPasswordLen, dwKeyFileLen;
CString strData, strPassword, strKeyFile, strFile;

NotifyUserActivity();

if(pCopyDataStruct->lpData != NULL)
{
dwLen = (DWORD)_tcslen((LPCTSTR)pCopyDataStruct->lpData);
if(dwLen == 0) return TRUE;

strData = (LPCTSTR)pCopyDataStruct->lpData;
dwPasswordLen = pCopyDataStruct->dwData >> 16;
dwKeyFileLen = pCopyDataStruct->dwData & 0xffff;

if((dwPasswordLen + dwKeyFileLen) >= dwLen) return TRUE;

if(dwPasswordLen != 0) strPassword = strData.Mid(0, dwPasswordLen);
if(dwKeyFileLen != 0) strKeyFile = strData.Mid(dwPasswordLen, dwKeyFileLen);

if((dwPasswordLen + dwKeyFileLen) != 0)
strFile = strData.Right(strData.GetLength() - (int)dwPasswordLen - (int)dwKeyFileLen);
else strFile = strData;

if(strFile.GetLength() == 0) return TRUE;

OnFileClose();
if(m_bFileOpen == TRUE) return TRUE;

if((dwPasswordLen != 0) && (dwKeyFileLen != 0))
_OpenDatabase(strFile, strPassword, strKeyFile, FALSE, NULL);
else if(dwPasswordLen != 0)
_OpenDatabase(strFile, strPassword, NULL, FALSE, NULL);
else if(dwKeyFileLen != 0)
_OpenDatabase(strFile, NULL, strKeyFile, FALSE, NULL);
else
_OpenDatabase(strFile, NULL, NULL, FALSE, NULL);

if((m_bMinimized == TRUE) || (m_bShowWindow == FALSE)) OnViewHide();
}

return TRUE;

}

EDIT: I hope it's the correct function type now. I don't use MFC.

spynet
July 19th, 2005, 10:10 AM
Hi,
now I have the follow error...

error C2440: "static_cast": impossibile convertire da "BOOL (__thiscall CPwSafeDlg::* )(CWnd *,WPARAM,LPARAM)" a "LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)"..... :cry:

NoHero
July 19th, 2005, 10:32 AM
ON_MESSAGE( /* ... */ )

Always requires a member function with the following header:

LRESULT CMyWindow::OnMessage ( WPARAM wParam, LPARAM lParam );

So try to use

ON_WM_COPYDATA( /* ... */ )

Instead.

spynet
July 19th, 2005, 11:04 AM
Hi,
I am confused,

I must use ON_WM_COPYDATA( /* ... */ ) instead of ON_MESSAGE(WM_COPYDATA, OnCopyData)...

Sorry but I not understand..... :confused:

philkr
July 19th, 2005, 11:33 AM
Did it work with my correcte version? I'm curious.

spynet
July 19th, 2005, 11:40 AM
Hi,
you can download the source code from http://keepass.sourceforge.net/

I use visual studio .net 7.1- framework 1.1

I await.. your solution....
Thanks for your patience

philkr
July 19th, 2005, 11:50 AM
I mean. Do you still have errors with the version I posted before. Because I edited it. It's different from the version you already tested and about which you said it would still have errors.

spynet
July 20th, 2005, 04:49 AM
Hi,
Now it's ok. Thank you very much for your patience and for your attention. I have understand the solution and why there was the error...

By and good holiday.

Crismer :wave: