Solved

IExplorer controled from Visual C++ 5

Posted on 1997-08-12
8
618 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:gvg
  • 4
  • 4
8 Comments
 
LVL 1

Author Comment

by:gvg
ID: 1403723
Edited text of question
0
 
LVL 3

Accepted Solution

by:
vinniew earned 200 total points
ID: 1403724
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
 
LVL 1

Author Comment

by:gvg
ID: 1403725
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
 
LVL 3

Expert Comment

by:vinniew
ID: 1403726
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:gvg
ID: 1403727
Looking forward to see more
0
 
LVL 3

Expert Comment

by:vinniew
ID: 1403728
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
 
LVL 1

Author Comment

by:gvg
ID: 1403729
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
 
LVL 3

Expert Comment

by:vinniew
ID: 1403730
If you want IE to come up, use IWebBrowserApp.  It inherits IWebBrowser.

V

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now