以前一直不会使用VC两个对象互相持有对方引用!今天晚上忙了很长时间给解决了!以后注意使用的方法即可!
#include "ClientSocket.h"
class CCapture_ClientDlg : public CDialog
{
// Construction
public:
CClientSocket* lpSocket;这个类中包含有CCapture_ClientDlg的指针
。。。。
private:
};
class CCapture_ClientDlg ;
class CClientSocket
{
friend class CCapture_ClientDlg ;
public:
bool Run();
CClientSocket();
CClientSocket(HWND hOwner) ;
CClientSocket(CCapture_ClientDlg *pParent) ;
。。。。。。
CCapture_ClientDlg *pParent ;这个类中包含有CCieltSocket的指针
// CFile hFile;
};
注意:在CClientSocket的实现文件中还要包含#include "Capture_ClientDlg.h"
即:
#include "Capture_ClientDlg.h"
CClientSocket::CClientSocket()
{
}
CClientSocket::CClientSocket(HWND hOwner)
{
this->m_hWnd=hOwner ;
this->hSocket=socket(AF_INET, SOCK_DGRAM, 0) ;
if(INVALID_SOCKET == this->hSocket)
{
AfxMessageBox("Create socket failed!") ;
}
this->add_remote.sin_family=AF_INET;
this->add_remote.sin_port=htons(6767) ;
this->add_remote.sin_addr.s_addr=inet_addr("192.168.0.231");
}
CClientSocket::CClientSocket(CWnd *pParent)
{
this->pParent=(CCapture_ClientDlg*)pParent ;
this->hSocket=socket(AF_INET, SOCK_DGRAM, 0) ;
if(INVALID_SOCKET == this->hSocket)
{
AfxMessageBox("Create socket failed!") ;
}
this->add_remote.sin_family=AF_INET;
this->add_remote.sin_port=htons(6767) ;
this->add_remote.sin_addr.s_addr=inet_addr("192.168.0.231");
}