BOOL CommonStrMethod::GetLocalHostNameAndIP(CString& strHostName, CString& strHostIP) { BOOL bRes = TRUE; WSADATA wsaData; CHAR szHostName[255] = {0}; CHAR* szIP = NULL; PHOSTENT phostinfo; if ( WSAStartup( MAKEWORD(2,2), &wsaData ) == 0 ) { if( gethostname( szHostName, 255) == 0) { if((phostinfo = gethostbyname(szHostName)) != NULL) { //这些就是获得IP的函数 szIP= inet_ntoa (*(struct in_addr *)*phostinfo->h_addr_list); } else { bRes = FALSE; //AfxMessageBox(_T("error:gethostbyname")); } } else { bRes = FALSE; //AfxMessageBox(_T("error:gethostname")); } WSACleanup(); } else { bRes = FALSE; AfxMessageBox(_T("error:gethostname")); } Char2WChar(strHostName.GetBuffer(), strlen(szHostName)+2, szHostName); if(szIP) { Char2WChar(strHostIP.GetBuffer(), strlen(szIP)+2, szIP); } return bRes; }
CString CommonStrMethod::GetLocalHostName() { BOOL bRes = TRUE; WSADATA wsaData; CHAR szHostName[255] = {0}; CHAR* szIP = NULL; PHOSTENT phostinfo; if ( WSAStartup( MAKEWORD(2,2), &wsaData ) == 0 ) { if( gethostname( szHostName, 255) == 0) { if((phostinfo = gethostbyname(szHostName)) != NULL) { //这些就是获得IP的函数 szIP= inet_ntoa (*(struct in_addr *)*phostinfo->h_addr_list); } else { bRes = FALSE; } } else { bRes = FALSE; } WSACleanup(); } else { bRes = FALSE; } WCHAR wszHostName[255] = {0}; Char2WChar(wszHostName, 255, szHostName); //WCHAR wszIP[128] = {0}; //Char2WChar(wszIP, 255, szIP); return wszHostName; }
void DiCodeConvert::UTF8_2Unicode( const char* in,std::wstring& out,int inlen/*=-1*/ ) { Char2WChar(CP_UTF8,in,out,inlen); }
void DiCodeConvert::UTF8_2Unicode( const char* in,wchar_t out[],int outsize,int inlen/*=-1*/ ) { Char2WChar(CP_UTF8,in,out,outsize,inlen); }
void DiCodeConvert::MultiByte2Unicode( const char* in,wchar_t out[],int outsize,int inlen ) { Char2WChar(CP_ACP,in,out,outsize,inlen); }