CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2012
    Posts
    25

    Question 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 ?

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to call function in ALT project C++?

    Quote Originally Posted by headshot View Post
    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 ?
    1. What is "a project ALT in C++"?
    2. What exactly "don`t you known how to call"?
    3. Where are these "code line 30-59 and line 98-109"?


    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2012
    Posts
    25

    Re: How to call function in ALT project C++?

    Quote Originally Posted by VictorN View Post
    1. What is "a project ALT in C++"?
    2. What exactly "don`t you known how to call"?
    3. 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;
                        //    }    
                        //}

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to call function in ALT project C++?

    Quote Originally Posted by headshot View Post
    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.

    Quote Originally Posted by headshot View Post
    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

  5. #5
    Join Date
    Jul 2012
    Posts
    25

    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

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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
  •  





Click Here to Expand Forum to Full Width

Featured