Click to See Complete Forum and Search --> : [RESOLVED] ON_MESSAGE compile error


EirikO
June 29th, 2007, 02:16 AM
I have the following code:

BEGIN_MESSAGE_MAP(CTCPClientAppDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CTCPClientAppDlg::OnBnClickedButton1)
ON_MESSAGE(WM_MYSOCKET_ONCONNECT, OnMySocketConnect)
ON_MESSAGE(WM_MYSOCKET_ONRECEIVE, OnMySocketReceive)
END_MESSAGE_MAP()


When I try to build the Solution, I get:

1>------ Build started: Project: TCPClientApp, Configuration: Debug Windows Mobile 5.0 Pocket PC SDK (ARMV4I) ------
1>Compiling...
1>TCPClientAppDlg.cpp
1>.\TCPClientAppDlg.cpp(33) : error C2143: syntax error : missing '}' before ';'
1>.\TCPClientAppDlg.cpp(33) : error C2143: syntax error : missing '}' before ';'
1>.\TCPClientAppDlg.cpp(33) : error C2143: syntax error : missing ';' before ','
1>.\TCPClientAppDlg.cpp(33) : error C2059: syntax error : ','
1>.\TCPClientAppDlg.cpp(34) : error C2143: syntax error : missing ';' before '{'
1>.\TCPClientAppDlg.cpp(34) : error C2447: '{' : missing function header (old-style formal list?)
1>.\TCPClientAppDlg.cpp(34) : error C2059: syntax error : ','
1>.\TCPClientAppDlg.cpp(35) : error C2143: syntax error : missing ';' before '{'
1>.\TCPClientAppDlg.cpp(35) : error C2447: '{' : missing function header (old-style formal list?)
1>.\TCPClientAppDlg.cpp(35) : error C2059: syntax error : '}'
1>.\TCPClientAppDlg.cpp(35) : error C2653: 'TheBaseClass' : is not a class or namespace name
1>.\TCPClientAppDlg.cpp(35) : error C2065: 'GetThisMessageMap' : undeclared identifier
1>.\TCPClientAppDlg.cpp(35) : error C2065: '_messageEntries' : undeclared identifier
1>.\TCPClientAppDlg.cpp(35) : error C2059: syntax error : 'return'
1>.\TCPClientAppDlg.cpp(35) : error C2059: syntax error : '}'
1>.\TCPClientAppDlg.cpp(41) : error C2143: syntax error : missing ';' before '{'
1>.\TCPClientAppDlg.cpp(41) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://c:\MyDocs\Visual Studio 2005\Projects\TCPClientApp\TCPClientApp\Windows Mobile 5.0 Pocket PC SDK (ARMV4I)\Debug\BuildLog.htm"
1>TCPClientApp - 17 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


100000$ question: Why?

Some additional info:

ON_MESSAGE(WM_MYSOCKET_ONCONNECT, OnMySocketConnect) is line 33.


In MySocket.h I have:

#define WM_MYSOCKET_ONACCEPT (WM_USER + 1);
//afx_msg LRESULT OnMySocketAccept(WPARAM wParam, LPARAM lParam);
//ON_MESSAGE(WM_MYSOCKET_ONACCEPT, OnMySocketAccept);
#define WM_MYSOCKET_ONCONNECT (WM_USER + 2);
//afx_msg LRESULT OnMySocketConnect(WPARAM wParam, LPARAM lParam);
//ON_MESSAGE(WM_MYSOCKET_ONCONNECT, OnMySocketConnect);
#define WM_MYSOCKET_ONRECEIVE (WM_USER + 3);
//afx_msg LRESULT OnMySocketReceive(WPARAM wParam, LPARAM lParam);
//ON_MESSAGE(WM_MYSOCKET_ONRECEIVE, OnMySocketReceive);
#define WM_MYSOCKET_ONCLOSE (WM_USER + 4);
//afx_msg LRESULT OnMySocketClose(WPARAM wParam, LPARAM lParam);
//ON_MESSAGE(WM_MYSOCKET_ONCLOSE, OnMySocketClose);



And in TCPClientAppDlg.h:

protected:
afx_msg LRESULT OnMySocketConnect(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnMySocketReceive(WPARAM wParam, LPARAM lParam);


TCPClientAppDlg.cpp:

LRESULT CTCPClientAppDlg::OnMySocketReceive(WPARAM wParam, LPARAM lParam)
{
BYTE Data[256] = {0};
int BytesRecieved = m_MySocket.Receive(Data, sizeof(Data));

if(BytesRecieved > 0)
{
m_OutputCtrl.AddString(_T("Received:"));
[.....]

S_M_A
June 29th, 2007, 02:53 AM
You most likely have a curly braces mismatch

EirikO
June 29th, 2007, 03:17 AM
But I can't figure it out.. I post the whole code, so maybe some of you has better eyes than me.. ;)


// TCPClientAppDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TCPClientApp.h"
#include "TCPClientAppDlg.h"
#include "MySocket.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CTCPClientAppDlg dialog

CTCPClientAppDlg::CTCPClientAppDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTCPClientAppDlg::IDD, pParent)
, m_Msg(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTCPClientAppDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_OutputCtrl);
DDX_Text(pDX, IDC_EDIT1, m_Msg);
}

BEGIN_MESSAGE_MAP(CTCPClientAppDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CTCPClientAppDlg::OnBnClickedButton1)
ON_MESSAGE(WM_MYSOCKET_ONCONNECT, OnMySocketConnect)
ON_MESSAGE(WM_MYSOCKET_ONRECEIVE, OnMySocketReceive)
END_MESSAGE_MAP()


// CTCPClientAppDlg message handlers

BOOL CTCPClientAppDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
SetupConnection();

return TRUE; // return TRUE unless you set the focus to a control
}

#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CTCPClientAppDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
DRA::RelayoutDialog(
AfxGetInstanceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_TCPCLIENTAPP_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_TCPCLIENTAPP_DIALOG));
}
#endif

LRESULT CTCPClientAppDlg::OnMySocketConnect(WPARAM wParam, LPARAM lParam)
{
int ErrorCode = (int)wParam;
if(ErrorCode == 0)
{
m_OutputCtrl.AddString(_T("Connection succeeded"));
BYTE Data[] = "Hello";
DWORD Length = sizeof(Data);
m_MySocket.Send(Data, Length);
} else
{
CString ErrorMsg;
ErrorMsg.Format(_T("Connection failed, error code %d."), m_MySocket.GetLastError());
m_OutputCtrl.AddString((LPCTSTR)ErrorMsg);
}
return 0;
}

LRESULT CTCPClientAppDlg::OnMySocketReceive(WPARAM wParam, LPARAM lParam)
{
BYTE Data[256] = {0};
int BytesRecieved = m_MySocket.Receive(Data, sizeof(Data));

if(BytesRecieved > 0)
{
m_OutputCtrl.AddString(_T("Received:"));
//Hexdump
} else
{
CString ErrorMsg;
ErrorMsg.Format(_T("Receive faild with error %d."),m_MySocket.GetLastError());
m_OutputCtrl.AddString((LPCTSTR)ErrorMsg);
}

m_OutputCtrl.AddString(_T("Shutting down."));
m_MySocket.ShutDown(CSocket::both);
m_OutputCtrl.AddString(_T("Closing"));
m_MySocket.Close();
m_OutputCtrl.AddString(_T("Finish"));

return 0;
}

void CTCPClientAppDlg::SetupConnection()
{
m_MySocket.m_Hwnd = m_hWnd;

m_OutputCtrl.AddString(_T("Creating socket"));
if(m_MySocket.Create()) {
CString LocalAddress;
UINT LocalPort = 0;
CString AddressToServer;
AddressToServer.Format(_T("163.34.104.153"));
UINT PortToServer = 2101;

m_MySocket.GetSockName(LocalAddress, LocalPort);

CString Message;
Message.Format(_T("Socket created on %s:%u"),LocalAddress, LocalPort);
m_OutputCtrl.AddString((LPCTSTR)Message);

Message.Format(_T("Connection to %s:%u"), AddressToServer, PortToServer);
m_OutputCtrl.AddString((LPCTSTR)Message);

m_MySocket.Connect(AddressToServer, PortToServer);
} else
{
m_OutputCtrl.AddString(_T("Socket creation failed"));
}
}

void CTCPClientAppDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);

CString Msg = m_Msg;
DWORD Length = Msg.GetLength();

m_OutputCtrl.AddString(_T("Sending your message..."));
m_OutputCtrl.AddString(Msg);
Msg += "\n\r";
m_MySocket.Send(Msg, Length+2);
m_Msg.Empty();
UpdateData(FALSE);
}

S_M_A
June 29th, 2007, 03:46 AM
Argh, please use code tags (see FAQ). Code is very hard to read presented like this so please edit your posts.

S_M_A
June 29th, 2007, 04:02 AM
Couldn't find any mismatch. A long shot however... Adding an & like this in one of my old projects:ON_BN_CLICKED(IDC_BUTTON1, &CTCPClientAppDlg::OnBnClickedButton1)gives the same type of error.

EirikO
June 29th, 2007, 04:05 AM
Argh, please use code tags (see FAQ). Code is very hard to read presented like this so please edit your posts.
Sorry!

A postet the code here: http://pastebin.com/938859

Thanks for your help!

EirikO
June 29th, 2007, 05:31 AM
Couldn't find any mismatch. A long shot however... Adding an & like this in one of my old projects:ON_BN_CLICKED(IDC_BUTTON1, &CTCPClientAppDlg::OnBnClickedButton1)gives the same type of error.

It has to be something with the two other lines..

ON_BN_CLICKED(IDC_BUTTON1, &CTCPClientAppDlg::OnBnClickedButton1)
ON_MESSAGE(WM_MYSOCKET_ONCONNECT, OnMySocketConnect)
ON_MESSAGE(WM_MYSOCKET_ONRECEIVE, OnMySocketReceive)


When I comment out (//) the 2. and 3. liner over, I can compile..

I have added the messages manual, can there be anyting I have forgotten some place? (If visual studio usually add this.. (how?))

All the same with extra (or less) "&CTCPClientAppDlg::"

S_M_A
June 29th, 2007, 06:21 AM
Good, you've added code tags! Easier to read now don't you think? :)

I always let class wizard add those macros so I actually don't know how they work (have never needed to bother)

Most likelely it's those two lines that are the reason. I checked help for ON_MESSAGE and it says:ON_MESSAGE(message, memberFxn )so I think the proper lines should beON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_MESSAGE(WM_MYSOCKET_ONCONNECT, OnMySocketConnect)
ON_MESSAGE(WM_MYSOCKET_ONRECEIVE, OnMySocketReceive)

miteshpandey
June 29th, 2007, 06:22 AM
#define WM_MYSOCKET_ONACCEPT (WM_USER + 1);
............
............
............

Remove all the ";"'s in #define and try again

S_M_A
June 29th, 2007, 06:30 AM
That's also true miteshpandey. Missed them in the first postings. Yet another good reason for using code tags. ;)

EirikO
June 29th, 2007, 07:28 AM
#define WM_MYSOCKET_ONACCEPT (WM_USER + 1);
............
............
............

Remove all the ";"'s in #define and try again

THANK YOU!!

Takk til deg også S M A!!

S_M_A
June 29th, 2007, 07:39 AM
You're welcome. :wave:

Please also mark the thread as resolved.

EirikO
July 2nd, 2007, 01:49 AM
I always let class wizard add those macros so I actually don't know how they work (have never needed to bother)

How does this work in Visual Studio 2005? If I'm correct the ClassWizrd are remvoved?

S_M_A
July 2nd, 2007, 02:08 AM
It's not completely removed it's just hiding... :) (Took awhile for me to find as well)
Right click on dialog and then add class, add variable and so on should show up.

EirikO
July 2nd, 2007, 02:23 AM
It's not completely removed it's just hiding... :) (Took awhile for me to find as well)
Right click on dialog and then add class, add variable and so on should show up.
Hmm. Ok..
But how to add the OnConnect-things?
It seems that my OnMySocketConnect isn't called, so I think I have done some mistakes when I added the code in the posts over...

S_M_A
July 2nd, 2007, 03:17 AM
Right click on button (or other control) and select Add event handler