MFC对话框OnInitDialog()中放入创建线程来实现端口监听,报错local function definitions are illegal解决思路

MFC对话框OnInitDialog()中放入创建线程来实现端口监听,报错local function definitions are illegal
error C2601: 'ThreadFunc' : local function definitions are illegal

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

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// 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
//************************************************************
UINT CUdprecvDlg::ThreadFunc(LPVOID pParam)
{
//线程函数实现

//启动SOCKET库,版本为2.0
WSAStartup(0x0202,&wsdata);
optval=TRUE;
//然后赋值给两个地址,一个用来绑定套接字,一个用来从网络上的广播地址接收消息;
a.sin_family=AF_INET;
a.sin_addr.s_addr=0;
a.sin_port=htons(5050);

from.sin_family=AF_INET;
from.sin_addr.s_addr=INADDR_BROADCAST;
from.sin_port=htons(5050);

int fromlength=sizeof(SOCKADDR);
//用UDP初始化套接字
s=socket(AF_INET,SOCK_DGRAM,0);
//设置该套接字为广播类型,
setsockopt(s,SOL_SOCKET,SO_BROADCAST,(char FAR *)&optval,sizeof(optval));
bind(s,(sockaddr *)&a,sizeof(sockaddr_in));
char buf[256];
CEdit * ce;
ce=(CEdit*)GetDlgItem(IDC_RecvMsg);
while(1)
{//从广播地址接收消息,注意用来绑定的地址和接收消息的地址是不一样的
recvfrom(s,buf,256,0,(struct sockaddr FAR *)&from,(int FAR *)&fromlength);

ce->SetWindowText(buf);
ZeroMemory(buf,256);
}

//*****************************************************************

}
CWinThread *m_pThread; //线程指针
m_pThread = AfxBeginThread(ThreadFunc, NULL); //启动线程
return TRUE; // return TRUE unless you set the focus to a control
}

------解决方案--------------------
不能在函数体内定义函数.
把UINT CUdprecvDlg::ThreadFunc(LPVOID pParam)放到OnInitDialog函数体外定义