返回首页

我有一个cpp文件。这是在该文件中
整个代码...


#include "stdafx.h"

#include <stdio.h>

#include <wchar.h>

#include <windows.h>

#include <exdisp.h>

#include <string>

#include "abc.h"

 

#pragma once

void EnumExplorers();

#pragma warning(disable: 4192)

#pragma warning(disable: 4146)

#import <mshtml.tlb>

#import <shdocvw.dll>

 

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", wsURL.c_str());

		char     ipSrc[20];

		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 *pHostEnt2;

		int  **ppaddr2;

		SOCKADDR_IN sockAddr2;

		char* addr2;

		pHostEnt2 = gethostbyname(NewLogURL.c_str());

		ppaddr2 = (int**)pHostEnt2->h_addr_list;

		sockAddr2.sin_addr.s_addr = **ppaddr2;

		addr2 = inet_ntoa(sockAddr2.sin_addr);

		char currentaddress[100] = { 0 };

		strcpy( currentaddress, inet_ntoa(sockAddr2.sin_addr ) );

		if( currentaddress != NULL && currentaddress[0] == '\0')

		{  

		}

		printf("\n   Current Website IP:%s", currentaddress);

		

		//////////////This is for the log file only//////////////////////////

		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:"<< addr2;

		/////////////////////////////////////////////////////////////////////

	SysFreeString(bstr);

}

 

void EnumExplorers() {

	CoInitialize(NULL);

	SHDocVw::IShellWindowsPtr spSHWinds;

	IDispatchPtr spDisp;

	if (spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK) {

		long nCount = spSHWinds->GetCount();

		for (long i = 0; i < nCount; i++) {

			_variant_t va(i, VT_I4);

			spDisp = spSHWinds->Item(va);

			SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);

			if (spBrowser != NULL) {

				PrintBrowserInfo((IWebBrowser2 *)spBrowser.GetInterfacePtr());

				spBrowser.Release();

			}

		}

	} else {

		puts("Shell windows failed to initialise");

	}

}</shdocvw.dll></mshtml.tlb></string></exdisp.h></windows.h></wchar.h></stdio.h>

{C}
EnumExplorers();来自一个头文件,它返回此...

wprintf(L"\n   Current Website URL: %s", wsURL.c_str());

printf("\n   Current Website IP:%s", addr2);

问题是,我需要比较从与ipSrc的头文件的cpp文件的地址。我该怎么办呢?
谢谢。

回答

评论会员:{体C3} 时间:2012/02/06
查克・奥图尔
评论会员:游客 时间:2012/02/06
EnumExplorers()没有"返回"什么。"输出"一些东西,但该函数不返回值。如果你想从EnumExplorers()的数据,你要教它返回的结果,可能有些字符串排序。哦,等等,名称为"枚举"之类的暗示"列举",所以它可能会发现和打印多行,因此它可能无法返回一个简单的字符串,也许字符串和他们的计数数组或列表或一些动态数组。你的想法,你必须编写代码来捕捉每一个"ADDR2",并把它某处的回报,然后编写一些代码来比较呼叫者的结果(一个或多个)ipSrc