IExplorer controled from Visual C++ 5

I have been trying to run Internet Explorer from my program.
This doesn't seem to work.  I have looked at the help that
comes with VC5 and I can see that there is a CLSID_IExplorer
defined there.  I tried that with CoGetClassObject but VC5 didn't
know anything about this classID.
The help also says something about IWebBrowserApp but VC5
Doesn't know that type either.
Well I could go on for every about all my stupid tries to get this to work.  I haven't done any COM programming before so I am probably doing something wrong here.
So what a want to ask is for VC code that can start or take over IE and hand me an object that I can use with all the functions defined in the help.  I don't need a complete program just code to do this.
LVL 1
gvgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gvgAuthor Commented:
Edited text of question
0
vinniewCommented:
Here's the answer:

You need to find the exact IID of Internet explorer in the registry, first.  It's going to depend on version number, so you'll have to check those.

It will be in HKEY_CLASSES_ROOT.


Then, you can start using COM.  

Here's what is going on:
COM API function uses CLSID to look up the filename in the registry(iexplore.exe) and where it's at.  Then, it searches for the vtable in the binary that stores all the function pointers.  The pointers are in a specific order.  If you know what parameters they take and have them defined correctly, you can now use them.

Basically, what you are doing is:

pUnknown->vTable->Foo()

The COM API will get you the pUnknown, but you have to have the interface struct.

Do you really have something like this:

MyInterfaceExplorer : public IUnknown
{
   int home(void);
...
...
...
};

?

I don't know where you got that, but it's the list of how the function pointers are ordered in the iexplore.exe vtable.

You can use CoCreateInstanceEx to start up your COM object and get the pUnknown, but I need that Interface definition if you want sample code.

Oh, one other thing.  VB uses a standard function pointer in the vtable, GetIDSOfNames(), to use the functions via another function.  You might have better luck with that, although it's slower.


Send the Interface struct if you want more.

V


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gvgAuthor Commented:
Well I don't have the Interface struct but in the ActiveX SDK from Microsoft the "class" or "Interface" is defined.
2 interfaces are defined there, the IWebBrowserApp and IWebBrowser where IWebBrowserApp is a superset of IWebBrowser.
I found the GUID for IExplorer in the registry and then used a macro called
DEFINE_GUID( ... )
This didn't link because DEFINE_GUID is somekind of extern macro and a also don't have REFIDs for thoes 2 interfaces.
What I was hoping for is that here is somewhere a include file witch defines IWebBrowserApp and IWebBrowser and also has the REFID's for thoes interfaces.  If there is none why do the put this into the ActiveX SDK?
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

vinniewCommented:
Here is a small part of exdisp.h where I found the IWebBrowser interface:

/* Definition of interface: IWebBrowser */
#undef INTERFACE
#define INTERFACE IWebBrowser

DECLARE_INTERFACE_(IWebBrowser, IDispatch)
{
#ifndef NO_BASEINTERFACE_FUNCS

    /* IUnknown methods */
    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
    STDMETHOD_(ULONG, AddRef)(THIS) PURE;
    STDMETHOD_(ULONG, Release)(THIS) PURE;

    /* IDispatch methods */
    STDMETHOD(GetTypeInfoCount)(THIS_ UINT FAR* pctinfo) PURE;

    STDMETHOD(GetTypeInfo)(
      THIS_
      UINT itinfo,
      LCID lcid,
      ITypeInfo FAR* FAR* pptinfo) PURE;

    STDMETHOD(GetIDsOfNames)(
      THIS_
      REFIID riid,
      OLECHAR FAR* FAR* rgszNames,
      UINT cNames,
      LCID lcid,
      DISPID FAR* rgdispid) PURE;

    STDMETHOD(Invoke)(
      THIS_
      DISPID dispidMember,
      REFIID riid,
      LCID lcid,
      WORD wFlags,
      DISPPARAMS FAR* pdispparams,
      VARIANT FAR* pvarResult,
      EXCEPINFO FAR* pexcepinfo,
      UINT FAR* puArgErr) PURE;
#endif

    /* IWebBrowser methods */
    STDMETHOD(GoBack)(THIS) PURE;
    STDMETHOD(GoForward)(THIS) PURE;
    STDMETHOD(GoHome)(THIS) PURE;
    STDMETHOD(GoSearch)(THIS) PURE;
    STDMETHOD(Navigate)(THIS_ BSTR URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers) PURE;
    STDMETHOD(Refresh)(THIS) PURE;
    STDMETHOD(Refresh2)(THIS_ VARIANT FAR* Level) PURE;
    STDMETHOD(Stop)(THIS) PURE;
    STDMETHOD(get_Application)(THIS_ IDispatch * FAR* ppDisp) PURE;
    STDMETHOD(get_Parent)(THIS_ IDispatch * FAR* ppDisp) PURE;
    STDMETHOD(get_Container)(THIS_ IDispatch * FAR* ppDisp) PURE;
    STDMETHOD(get_Document)(THIS_ IDispatch * FAR* ppDisp) PURE;
    STDMETHOD(get_TopLevelContainer)(THIS_ VARIANT_BOOL FAR* pBool) PURE;
    STDMETHOD(get_Type)(THIS_ BSTR FAR* pbstrType) PURE;
    STDMETHOD(get_Left)(THIS_ long FAR* pl) PURE;
    STDMETHOD(put_Left)(THIS_ long Left) PURE;
    STDMETHOD(get_Top)(THIS_ long FAR* pl) PURE;
    STDMETHOD(put_Top)(THIS_ long Top) PURE;
    STDMETHOD(get_Width)(THIS_ long FAR* pl) PURE;
    STDMETHOD(put_Width)(THIS_ long Width) PURE;
    STDMETHOD(get_Height)(THIS_ long FAR* pl) PURE;
    STDMETHOD(put_Height)(THIS_ long Height) PURE;
    STDMETHOD(get_LocationName)(THIS_ BSTR FAR* pbstrLocationName) PURE;
    STDMETHOD(get_LocationURL)(THIS_ BSTR FAR* pbstrLocationURL) PURE;
    STDMETHOD(get_Busy)(THIS_ VARIANT_BOOL FAR* pBool) PURE;
};

I'll write more tomorrow, but this will be part of the #includes...

TTFN

V

0
gvgAuthor Commented:
Looking forward to see more
0
vinniewCommented:
Ok,

So you have the interface included somewhere...

You can then use something like:
DEFINE_GUID(yatta,yatta,yatta)

 hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);    // make sure the project has COM/Automation settings, too.
 IWebBrowser *pPoint = 0;
 CoCreateInstance(CLSID_Browser, 0,
                  CLSCTX_INPROC_SERVER,
                  IID_IWebBrowser, (void**)&pPoint);


This will get you a pointer to pUnknown.  The WebBrowser class structure is nested in this.  So, something like:

DWORD dwHeight = pPoint->get_Height() should then function


I'll test this out today sometime...

V

0
gvgAuthor Commented:
I tried this last night and my CoCreateInstance return S_OK whitch is good.
But my problem was that when I
CLSID_InternetExplorer witch was OK and IID_IWebBrowser witch was not OK because it didn't link.  I read somewhere that this DEFINE_GUID macro had 2 diffrent implimentations and one of the was extern.
I looked at exdisp.h where both of this GUIDs are defined but I couldn't see any diffrance in them.
So CoCreateInstance worked only if I used
CLSID_InternetExplorer and IID_IUnknown.
I didn't see any IE come up and when I tried some functions it didn't work.


0
vinniewCommented:
If you want IE to come up, use IWebBrowserApp.  It inherits IWebBrowser.

V

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.