在基于对话框的程序中,加了个A类,,,在A类里声明.h中加个变量CClientDlg* pdlg;,且包含了Dlg的头文件.我在对话框的OnInitDialog();把this给pdlg,好在A类里操作对话框,,,,,但是程序报错,说pdlg没声明,,,高手给讲讲吧.....咋回事........代码如下,CMySocket就是加的类.................-----------------------------------------------------------------------------------/////////////////////////////////////////////////////////////////////////////
// CClientDlg dialogclass CClientDlg : public CDialog
{
// Construction
public:
CMySocket m_Client_Socket;
CClientDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CClientDlg)
enum { IDD = IDD_CLIENT_DIALOG };
CEdit m_SendEdit;
CEdit m_ReceiveEdit;
CIPAddressCtrl m_IP;
int m_SendType;
int m_ReceiveType;
int m_Port;
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CClientDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
HICON m_hIcon; // Generated message map functions
//{{AFX_MSG(CClientDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};----------------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// CClientDlg message handlersBOOL CClientDlg::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
m_Port=2404;
m_IP.SetAddress(10,100,100,1);
m_ReceiveType=0;
m_SendType=0;
//m_Client_Socket.plg=(CClientDlg *)(this);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}void CClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
----------------------------------------------------------------------------------------------#if !defined(AFX_MYSOCKET_H__45F56047_2B8C_4EC6_9888_0094B873EAED__INCLUDED_)
#define AFX_MYSOCKET_H__45F56047_2B8C_4EC6_9888_0094B873EAED__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MySocket.h : header file
//
#include "clientDlg.h"/////////////////////////////////////////////////////////////////////////////
// CMySocket command targetclass CMySocket : public CAsyncSocket
{
// Attributes
public:// Operations
public:
CMySocket();
virtual ~CMySocket();// Overrides
public:
CClientDlg* pdlg;
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMySocket)
//}}AFX_VIRTUAL // Generated message map functions
//{{AFX_MSG(CMySocket)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG// Implementation
protected:
};
----------------------------------------------------------------------------------------------------------Configuration: client - Win32 Debug--------------------
Compiling...
client.cpp
e:\client\mysocket.h(26) : error C2143: syntax error : missing ';' before '*'
e:\client\mysocket.h(26) : error C2501: 'CClientDlg' : missing storage-class or type specifiers
e:\client\mysocket.h(26) : error C2501: 'pdlg' : missing storage-class or type specifiers
clientDlg.cpp
e:\client\mysocket.h(26) : error C2143: syntax error : missing ';' before '*'
e:\client\mysocket.h(26) : error C2501: 'CClientDlg' : missing storage-class or type specifiers
e:\client\mysocket.h(26) : error C2501: 'pdlg' : missing storage-class or type specifiers
MySocket.cpp
e:\client\clientdlg.h(19) : error C2146: syntax error : missing ';' before identifier 'm_Client_Socket'
e:\client\clientdlg.h(19) : error C2501: 'CMySocket' : missing storage-class or type specifiers
e:\client\clientdlg.h(19) : error C2501: 'm_Client_Socket' : missing storage-class or type specifiers
Generating Code...
Error executing cl.exe.client.exe - 9 error(s), 0 warning(s)
// CClientDlg dialogclass CClientDlg : public CDialog
{
// Construction
public:
CMySocket m_Client_Socket;
CClientDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CClientDlg)
enum { IDD = IDD_CLIENT_DIALOG };
CEdit m_SendEdit;
CEdit m_ReceiveEdit;
CIPAddressCtrl m_IP;
int m_SendType;
int m_ReceiveType;
int m_Port;
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CClientDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
HICON m_hIcon; // Generated message map functions
//{{AFX_MSG(CClientDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};----------------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// CClientDlg message handlersBOOL CClientDlg::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
m_Port=2404;
m_IP.SetAddress(10,100,100,1);
m_ReceiveType=0;
m_SendType=0;
//m_Client_Socket.plg=(CClientDlg *)(this);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}void CClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
----------------------------------------------------------------------------------------------#if !defined(AFX_MYSOCKET_H__45F56047_2B8C_4EC6_9888_0094B873EAED__INCLUDED_)
#define AFX_MYSOCKET_H__45F56047_2B8C_4EC6_9888_0094B873EAED__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MySocket.h : header file
//
#include "clientDlg.h"/////////////////////////////////////////////////////////////////////////////
// CMySocket command targetclass CMySocket : public CAsyncSocket
{
// Attributes
public:// Operations
public:
CMySocket();
virtual ~CMySocket();// Overrides
public:
CClientDlg* pdlg;
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMySocket)
//}}AFX_VIRTUAL // Generated message map functions
//{{AFX_MSG(CMySocket)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG// Implementation
protected:
};
----------------------------------------------------------------------------------------------------------Configuration: client - Win32 Debug--------------------
Compiling...
client.cpp
e:\client\mysocket.h(26) : error C2143: syntax error : missing ';' before '*'
e:\client\mysocket.h(26) : error C2501: 'CClientDlg' : missing storage-class or type specifiers
e:\client\mysocket.h(26) : error C2501: 'pdlg' : missing storage-class or type specifiers
clientDlg.cpp
e:\client\mysocket.h(26) : error C2143: syntax error : missing ';' before '*'
e:\client\mysocket.h(26) : error C2501: 'CClientDlg' : missing storage-class or type specifiers
e:\client\mysocket.h(26) : error C2501: 'pdlg' : missing storage-class or type specifiers
MySocket.cpp
e:\client\clientdlg.h(19) : error C2146: syntax error : missing ';' before identifier 'm_Client_Socket'
e:\client\clientdlg.h(19) : error C2501: 'CMySocket' : missing storage-class or type specifiers
e:\client\clientdlg.h(19) : error C2501: 'm_Client_Socket' : missing storage-class or type specifiers
Generating Code...
Error executing cl.exe.client.exe - 9 error(s), 0 warning(s)
================
你这个是不是写错了
按你帖子里说的是不是应该是m_Client_Socket.pdlg
我都注释掉了,,,后编译的还是报错,,,
http://e.ys168.com/note/fd.htm?http://ys-F.ys168.com/?client.rar_50c5bsm0e0ekkism0cp5bitlm1bspr1bs0b5bitlm0cp2bu14z97f14z
将MySocket.h文件里面的#include "clientDlg.h"移到MySocket.cpp文件里面就可以了。如果你想继续在MySocket.h里面使用CClientDlg* pdlg;可以在前面加上 class CClientDlg;在头文件里面include其它头文件不是个什么好习惯,尽量在.cpp里面include别的头文件。
在dlg里,调用SetFunc()指定一个全局的处理函数。