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

📄 clocalmachine.cpp

📁 《DirectShow开发指南》配套代码代码,需要DirectX SDK 7以上支持。
💻 CPP
字号:
// CLocalMachine.cpp: implementation of the CLocalMachine class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CLocalMachine.h"

//#include <Winsock2.h>

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

//#pragma comment(lib, "Ws2_32.lib")
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLocalMachine::CLocalMachine()
{
	m_bInit = false;
	InitSystem();
}

CLocalMachine::~CLocalMachine()
{
	Uninit();
}

void CLocalMachine::InitSystem(void)
{
	if (m_bInit)
		return;

	// Init socket
	WORD     wVersionRequested = MAKEWORD(2, 0);
	WSADATA  wsaData;
	if (WSAStartup(wVersionRequested, &wsaData) == 0)
	{
		m_bInit = true;
	}

	// Other init...
	if (m_bInit)
	{
		//m_bInit = 
	}
}

void CLocalMachine::Uninit(void)
{
	// Clean up socket
	if (m_bInit)
	{
		WSACleanup();
	}
}

bool CLocalMachine::GetIPAddress(char * outIP, char * outHost)
{
	if (m_bInit)
	{
		char   name[255];
		if (gethostname(name, sizeof(name)) == 0)
		{
			// Output the host name
			if (outHost != NULL)
				strcpy(outHost, name);

			PHOSTENT  hostinfo;
			if((hostinfo = gethostbyname(name)) != NULL)
			{
				// Output local machine's IP address string
				LPCSTR pIP = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
				if (outIP != NULL)
					strcpy(outIP, pIP);
				return true;
			}
		}
	}
	return false;
}

⌨️ 快捷键说明

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