|
-
July 16th, 2012, 11:18 AM
#1
How to call function in ALT project C++?
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 ?
Code:
// 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]; ++i)
// {
// struct in_addr addr = { 0 };
// addr.s_addr = *(uint32_t*)hent->h_addr_list[i];
// 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 file\n";
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;
}
Using code line 30-59 and line 98-109 ?
-
July 16th, 2012, 12:56 PM
#2
Re: How to call function in ALT project C++?
 Originally Posted by headshot
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 ?
...
Using code line 30-59 and line 98-109 ?
- What is "a project ALT in C++"?
- What exactly "don`t you known how to call"?
- Where are these "code line 30-59 and line 98-109"?
Victor Nijegorodov
-
July 17th, 2012, 12:53 AM
#3
Re: How to call function in ALT project C++?
 Originally Posted by VictorN
- What is "a project ALT in C++"?
- What exactly "don`t you known how to call"?
- Where are these "code line 30-59 and line 98-109"?

Hi
1 ) ALT , it`s mean Active Template Library , using C++ code , write in Visual Studio 2005
2) Call Function
Code:
strings_t getip(string hostname)
and put in
Code:
STDMETHODIMP CBhoApp::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pvarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
//call function strings_t getip(string hostname)
//strings_t hosts = getip(string_sub);
//....
}
3) code line 30-59
Code:
// 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]; ++i)
// {
// struct in_addr addr = { 0 };
// addr.s_addr = *(uint32_t*)hent->h_addr_list[i];
// 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
line 98-109
Code:
//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;
// }
//}
-
July 17th, 2012, 01:22 AM
#4
Re: How to call function in ALT project C++?
 Originally Posted by headshot
Hi
1 ) ALT , it`s mean Active Template Library , using C++ code , write in Visual Studio 2005
No, Active Template Library is ATL, not ALT.
 Originally Posted by headshot
2) Call Function
Code:
strings_t getip(string hostname)
and put in
Code:
STDMETHODIMP CBhoApp::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pvarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
//call function strings_t getip(string hostname)
//strings_t hosts = getip(string_sub);
//....
}
First, your lines 30-59 and 98-109 are commented out. Why? Is this code being uncommented compilable?
Victor Nijegorodov
-
July 17th, 2012, 04:52 AM
#5
Re: How to call function in ALT project C++?
Hi Sir.
At line 30-59 and 98-109 , I will open it. But I do not know how to call it and execute, I'm afraid it will not run
-
July 17th, 2012, 05:12 AM
#6
Re: How to call function in ALT project C++?
So what do you want? To try to compile it yourself or to wait until someone from us would do it for you?
I'd suggest you to try to compile it yourself...
Besides, hat do you mean by "do not know how to call it and execute"? Don't you know how to use functions in C++?
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|