How to call function in ALT project C++?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello , I have a project ALT in C++. I want to check IP from file text , compare with url string . But I don`t known how to call it ?
<pre class="prettyprint // BhoApp.cpp : Implementation of CBhoApp
#include "stdafx.h"
#include "BhoNew.h"
#include "BhoApp.h"
#include "exdispid.h"
/////////////////////////////////////////////////////////////////////////////
// CBhoApp
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <stdio.h>
/////////////////////////////////////////////////////////////////////////////
#include <stdexcept>
#include <vector>

using namespace std;

#ifdef _WIN32
#include <WinSock2.h>
#include <WS2tcpip.h>
typedef unsigned uint32_t;
#else
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h> // BSD needs this
#endif

typedef vector<string> strings_t;

// function return IP
//strings_t getip(string hostname)
//{
// if (struct hostent* hent = gethostbyname(hostname.c_str()))
// {
// if (hent->h_addrtype == AF_INET && hent->h_length == sizeof(uint32_t))
// {
// strings_t hosts;
// for (int i = 0; hent->h_addr_list; ++i)
// {
// struct in_addr addr = { 0 };
// addr.s_addr = *(uint32_t*)hent->h_addr_list;
// hosts.push_back(inet_ntoa(addr));
// }
// return hosts;
// }
// string text = "";
// throw runtime_error(text);
// }
//
// string text = "";
// throw runtime_error(text);
//}

//#ifdef _WIN32
// WSADATA wsadata = { 0 };
// WSAStartup(MAKEWORD(2, 2), &wsadata);
//#endif

STDMETHODIMP CBhoApp::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pvarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
USES_CONVERSION; // This macro should be called when using ATL string conversion
// macros to avoid compile errors (here we are using OLE2T)

if(dispidMember == DISPID_BEFORENAVIGATE2)
{
BSTR bstrUrlName;
HRESULT hr = m_spWebBrowser2->get_LocationURL(&bstrUrlName);
if(FAILED(hr))
return hr;

LPTSTR psz = new TCHAR[SysStringLen(bstrUrlName)];
lstrcpy(psz, OLE2T(bstrUrlName));

string c=string(psz);
int count=0;
int count2=0;
string string_sub;
ifstream infile("E:\test.txt");
if (!infile)
{
cout << "Unable to open filen";
exit(1); // terminate with error
}
while(!infile.eof()) // To get you all the lines.
{
getline(infile,string_sub); // Saves the line in string_sub.
if (!string_sub.empty())
{
try
{
size_t result2 = c.find( string_sub ); //check string_sub on the text file line by line, comparable to string_main
if( result2 != string::npos ) // if found
{
count2+=1;
}
//strings_t hosts = getip(string_sub);
//for (strings_t::const_iterator p = hosts.begin(); p != hosts.end() ; ++p)
//{
// //cout << *p << endl;
//
// size_t result = c.find( (string)*p); //check string_sub on the text file line by line, comparable to string_main
//
// if( result != string::npos ) // if found
// {
// count+=1;
// }
//}
}
catch(const exception &e)
{
clog<<e.what()<<endl;
}
}
}
infile.close();
if (count2 != 0) // || (count != 0))
{
VARIANT vFlags = {0},vTargetFrameName = {0};
// Instead of about:blank, you can redirect user to some page saying site has been blocked. :-)
m_spWebBrowser2->Navigate(SysAllocString(L"about:blank"),&vFlags,&vTargetFrameName,NULL,NULL);
m_spWebBrowser2->put_Visible(VARIANT_TRUE);
return S_FALSE;
}
return S_OK;
}
return S_FALSE;
}[/code]
<br/>
<br/>
Using code line 30-59 and line 98-109 ?


View the full article
 
Back
Top