但有一个问题,我有这个代码的伟大工程。看来,偶尔约:空白弹出gethostbyname()的不能habdle和代码停止。有没有办法,我可以调整通过当前网址www.google.com或也许只是的gethostbyname跳过此代码来处理这个问题吗?这里是代码。
:7766180 |会员:保罗万岁void PrintBrowserInfo(IWebBrowser2 *pBrowser) {
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
BSTR bstr;
pBrowser->get_LocationURL(&bstr);
std::wstring wsURL;
wsURL = bstr;
size_t DSlashLoc = wsURL.find(L"://");
if (DSlashLoc != wsURL.npos)
{
wsURL.erase(wsURL.begin(), wsURL.begin() + DSlashLoc + 3);
}
DSlashLoc = wsURL.find(L"www.");
if (DSlashLoc == 0)
{
wsURL.erase(wsURL.begin(), wsURL.begin() + 4);
}
DSlashLoc = wsURL.find(L"/");
if (DSlashLoc != wsURL.npos)
{
wsURL.erase(DSlashLoc);
}
wprintf(L"\n Current Website URL: %s\n\n", wsURL.c_str());
int Newlength = WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, wsURL.c_str(), -1, NULL, 0, NULL, NULL);
std::string NewLogURL(Newlength+1, 0);
int Newresult = WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, wsURL.c_str(), -1, &NewLogURL[0],Newlength+1, NULL, NULL);
HOSTENT *pHostEnt;
int **ppaddr;
SOCKADDR_IN sockAddr;
char* addr;
pHostEnt = gethostbyname(NewLogURL.c_str());
ppaddr = (int**)pHostEnt->h_addr_list;
sockAddr.sin_addr.s_addr = **ppaddr;
addr = inet_ntoa(sockAddr.sin_addr);
printf("\n Current Website IP:%s", addr);
int length = WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, wsURL.c_str(), -1, NULL, 0, NULL, NULL);
std::string LogURL(length+1, 0);
int result = WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, wsURL.c_str(), -1, &LogURL[0],length+1, NULL, NULL);
myfile << "\n Current Website URL:" << LogURL;
myfile << "\n Current Website IP:"<< addr;
SysFreeString(bstr);
}