IWebBrowser2

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by maxfax, 30 Sep 2012.

  1. maxfax

    maxfax New Member

    Joined:
    23 Jun 2010
    Messages:
    25
    Likes Received:
    0
    Reputations:
    0
    Здравствуйте!
    Я не сильный знаток с++, мне нужно запустить IWebBrowser2 и перейти на нужный урл, вот код который я взял с msdn
    Code:
    if (SUCCEEDED(OleInitialize(NULL)))
    {
       IWebBrowser2*    pBrowser2;
    
       CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, 
                           IID_IWebBrowser2, (void**)&pBrowser2);
       if (pBrowser2)
       {
           VARIANT vEmpty;
           VariantInit(&vEmpty);
    
           BSTR bstrURL = SysAllocString(L"http://microsoft.com");
    
           HRESULT hr = pBrowser2->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);
           if (SUCCEEDED(hr))
           {
               pBrowser2->put_Visible(VARIANT_TRUE);
           }
           else
           {
               pBrowser2->Quit();
           }
    
           SysFreeString(bstrURL);
           pBrowser2->Release();
       }
    
       OleUninitialize();
    }
    
    я его вставил в свой проект но он упорно не хочет компилиться, помогите решить проблему.

    вот полный код, среда dev cpp
    Code:
    #include <windows.h>
    #include "Exdisp.h"
    
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    char szClassName[ ] = "WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
        
        if (SUCCEEDED(OleInitialize(NULL))) {
            IWebBrowser2*    pBrowser2;
            CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, 
                           IID_IWebBrowser2, (void**)&pBrowser2);
            if (pBrowser2)
            {
                VARIANT vEmpty;
                VariantInit(&vEmpty);
    
                BSTR bstrURL = SysAllocString(L"http://microsoft.com");
                HRESULT hr = pBrowser2->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);
                if(SUCCEEDED(hr))
                {
                   pBrowser2->put_Visible(VARIANT_TRUE);
                }
                else
                {
                   pBrowser2->Quit();
                }
    
                SysFreeString(bstrURL);
                pBrowser2->Release();
             }
             OleUninitialize();
          }
        
        while (GetMessage (&messages, NULL, 0, 0))
        {
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
        return messages.wParam;
    }
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  
        {
            case WM_DESTROY:
                PostQuitMessage (0);       
                break;
            default:                    
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
        return 0;
    }
    
    
    
    вот ошибки которые выдает компилятор
    Code:
     C:\Users\nout\Desktop\CPP\Browser\main.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': 
    60 C:\Users\nout\Desktop\CPP\Browser\main.cpp `CLSID_InternetExplorer' undeclared (first use this function) 
    
      (Each undeclared identifier is reported only once for each function it appears in.) 
     C:\Users\nout\Desktop\CPP\Browser\Makefile.win [Build Error]  [main.o] Error 1 
    
     
  2. Kaimi

    Kaimi Well-Known Member

    Joined:
    23 Aug 2007
    Messages:
    1,732
    Likes Received:
    811
    Reputations:
    231
    А ты в Visual Studio компилируй, там все ок
     
    _________________________
  3. maxfax

    maxfax New Member

    Joined:
    23 Jun 2010
    Messages:
    25
    Likes Received:
    0
    Reputations:
    0
    а нет у меня Visual Studio к сожалению, и скачать не могу так как скорость 10 кб/c
     
  4. maxfax

    maxfax New Member

    Joined:
    23 Jun 2010
    Messages:
    25
    Likes Received:
    0
    Reputations:
    0
    дайте выдачу этих переменных из VS

    Code:
    cout << CLSID_InternetExplorer;
    cout << CLSCTX_LOCAL_SERVER;
    cout << IID_IWebBrowser2;
    
    Спасибо!