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 ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// 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 ?
From the looks of it, you are coding a Browser Helper Object for Internet Explorer. It is a COM object and is therefore treated as such. Do you know COM? If not, you need to learn.

In general, a method of the COM object is called via a pointer to an object of the class. In COM, you usually have interface pointers, although that's really just required for the consumer of the object (Internet Explorer or others in this case).
You already opened one topic with pretty much the same subject if I remember correctly ......

What is "ALT" from topic title ? I suppose do you mean ATL (Active Template Library) ....

If you use ATL, what version are you using ? From using macros like USES_CONVERSION I suppose you still using ATL3, which is a very outdated version ..... If you are using ATL7 or higher, then this macro is not needed.

http://msdn.microsoft.com/en-us/library/87zae4a3%28VS.85%29.aspx
Last edited on
Topic archived. No new replies allowed.