#define AFX_CHATDLG_H__CA158545_90FE_4D51_8EB9_8AD271AFBB86__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000/////////////////////////////////////////////////////////////////////////////
// CChatDlg dialog
#define WM_RECVDATA WM_USER+1
struct RECVPARAM
{   
SOCKET sock;//报错,缺";"?
HWND hwnd;
};
class CChatDlg : public CDialog
{
// Construction
public:
static DWORD WINAPI RecvProc(LPVOID lpParameter);
BOOL InitSocket();
CChatDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CChatDlg)
enum { IDD = IDD_CHAT_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CChatDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
HICON m_hIcon; // Generated message map functions
//{{AFX_MSG(CChatDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnBtnSend();
//}}AFX_MSG
afx_msg void OnRecvData(WPARAM wParam,LPARAM lParam);
DECLARE_MESSAGE_MAP()
private:
SOCKET m_socket;
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_CHATDLG_H__CA158545_90FE_4D51_8EB9_8AD271AFBB86__INCLUDED_)编译时出错如下:
--------------------Configuration: Chat - Win32 Debug--------------------
Compiling...
Chat.cpp
e:\vc_myproject\project_windows\project_net\chat\chatdlg.h(16) : error C2146: syntax error : missing ';' before identifier 'sock'
e:\vc_myproject\project_windows\project_net\chat\chatdlg.h(16) : error C2501: 'SOCKET' : missing storage-class or type specifiers
我在工程设置中加了库:ws2_32.lib

解决方案 »

  1.   

    sorry, is SOCKET.
    你没加头文件?
      

  2.   

    #include <winsock2.h>#pragma comment(lib, "WS2_32.lib")
      

  3.   

    加个头文件
    #include <winsock2.h>
      

  4.   

    头方件倒是加了,但没加:
    #pragma   comment(lib,   "WS2_32.lib")现在OK了,谢谢大家,esp sjdev,thank you!
    ---再问一下,这句话起什么作用啊?我刚学,不是很清楚 !
      

  5.   

    刚刚又试了下,头文件加了:Winsock2.h
    但还是同样的错误!!!!
      

  6.   

    #pragma comment(lib,"WS2_32.lib") 这句话的意思是连接到Winsock2的静态库。
      

  7.   

    问题解决了.出错在:
    没有在StdAfx.h中加Afxsock.h头文件,因为我用到了AfxsockInit函数.
    而且,加了Afxsock.h后,就不用在库中再加载Winsock2.h了
    谢谢各位!
      

  8.   

    可以Afxsock.h然后,AfxsockInit
    也可Winsock2.h然后,WSAStartup
      

  9.   

    另:在AppWizard中选择Socket支持选项,会自动加入afxsock.h和AfxsockInit。