?? clocalmachine.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 + -