0

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?

yasar
  • 13,158
  • 28
  • 95
  • 160
  • 1
    Reading here might help get you enlightened: https://support.microsoft.com/en-us/kb/181473 – alk Oct 09 '15 at 08:36
  • @alk, your link is broke. Maybe add some google keywords so folk can find it? Microsoft are always breaking links. Thanks :-) – www-0av-Com Apr 30 '20 at 12:25
  • 1
    @www-0av-Com: Use this backup http://web.archive.org/web/20160314141831/https://support.microsoft.com/en-us/kb/181473/ – alk Apr 30 '20 at 15:10

1 Answers1

1

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.

yasar
  • 13,158
  • 28
  • 95
  • 160