1

According to MSDN documentation, you can create a COM object to access internet explorer like this in VB;

Dim IE As SHDocVw.InternetExplorer

Set IE = CreateObject("InternetExplorer.Application")

As far as I know, COM object supposed to be language independent. Therefore, I think it should be possible to do this in plain C (Not C++).

How can I create any COM object using plain C on Windows operating system?

3
  • 1
    Reading here might help get you enlightened: support.microsoft.com/en-us/kb/181473 Commented Oct 9, 2015 at 8:36
  • @alk, your link is broke. Maybe add some google keywords so folk can find it? Microsoft are always breaking links. Thanks :-) Commented Apr 30, 2020 at 12:25
  • 1
    @www-0av-Com: Use this backup web.archive.org/web/20160314141831/https://… Commented Apr 30, 2020 at 15:10

1 Answer 1

2

After some research, I solved my problem like this;

#include <windows.h>

#define COBJMACROS
#include <exdisp.h>

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{

    if (SUCCEEDED(OleInitialize(NULL)))
    {
       IWebBrowser2*    pBrowser2;

       CoCreateInstance(&CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, 
                           &IID_IWebBrowser2, (void**)&pBrowser2);
       if (pBrowser2)
       {
           BSTR bstrURL = SysAllocString(L"http://www.google.com");
           HRESULT hr;
           VARIANT vEmpty;


           VariantInit(&vEmpty);

           hr = IWebBrowser2_Navigate(pBrowser2, bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);
           if (SUCCEEDED(hr))
           {
               IWebBrowserApp_put_Visible(pBrowser2,VARIANT_TRUE);
           }
           else
           {
               IWebBrowser2_Quit(pBrowser2);
           }

           SysFreeString(bstrURL);
           IWebBrowser_Release(pBrowser2);
       }

       OleUninitialize();
    }

}

ExpDisp.h header file from Windows SDK contains internet explorer's COM interface. Moreover, it contains macros to easily call methods.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.