⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cwicnetexampledoc.cpp

📁 网络共XIANG
💻 CPP
字号:
// CWiCnetExampleDoc.cpp : implementation of the CCWiCnetExampleDoc class
//

#include "stdafx.h"
#include "CWiCnetExample.h"

#include "CWiCnetExampleDoc.h"
#include <winsock2.h>




#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleDoc

IMPLEMENT_DYNCREATE(CCWiCnetExampleDoc, CDocument)

BEGIN_MESSAGE_MAP(CCWiCnetExampleDoc, CDocument)
	//{{AFX_MSG_MAP(CCWiCnetExampleDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleDoc construction/destruction

CCWiCnetExampleDoc::CCWiCnetExampleDoc()
{
	m_strHostIP = "";
	
	WORD wVersionRequested;
	  WSADATA wsaData;

	  CString ip;

	  wVersionRequested = MAKEWORD( 2, 0 );

	  	char szHostName[128];

	  if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
	  {


		if( gethostname(szHostName, 128) == 0 )
		{
			// Get host adresses
			struct hostent * pHost;
			int i;
 
			pHost = gethostbyname(szHostName);
 
			for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
 			{
 				int j;
 
 				for( j = 0; j < pHost->h_length; j++ )
 				{
					 CString addr;
 
 					if( j > 0 )
 						m_strHostIP += ".";
 
 					addr.Format("%u", (unsigned int)((unsigned
		 			char*)pHost->h_addr_list[i])[j]);
					m_strHostIP += addr;
 				}
  				// str now contains one local IP address - do whatever you want to do with it (probably add it to a list)
        
				WSACleanup( );
			  } 
		}
	}
	m_strHostName = szHostName;
}

CCWiCnetExampleDoc::~CCWiCnetExampleDoc()
{
}

BOOL CCWiCnetExampleDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleDoc serialization

void CCWiCnetExampleDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleDoc diagnostics

#ifdef _DEBUG
void CCWiCnetExampleDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CCWiCnetExampleDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleDoc commands

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -