gvg
asked on
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
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_(IWebBro wser, 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)(T HIS_ IDispatch * FAR* ppDisp) PURE;
STDMETHOD(get_Document)(TH IS_ IDispatch * FAR* ppDisp) PURE;
STDMETHOD(get_TopLevelCont ainer)(THI S_ 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
/* Definition of interface: IWebBrowser */
#undef INTERFACE
#define INTERFACE IWebBrowser
DECLARE_INTERFACE_(IWebBro
{
#ifndef NO_BASEINTERFACE_FUNCS
/* IUnknown methods */
STDMETHOD(QueryInterface)(
STDMETHOD_(ULONG, AddRef)(THIS) PURE;
STDMETHOD_(ULONG, Release)(THIS) PURE;
/* IDispatch methods */
STDMETHOD(GetTypeInfoCount
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)
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)
STDMETHOD(get_Parent)(THIS
STDMETHOD(get_Container)(T
STDMETHOD(get_Document)(TH
STDMETHOD(get_TopLevelCont
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_
STDMETHOD(put_Width)(THIS_
STDMETHOD(get_Height)(THIS
STDMETHOD(put_Height)(THIS
STDMETHOD(get_LocationName
STDMETHOD(get_LocationURL)
STDMETHOD(get_Busy)(THIS_ VARIANT_BOOL FAR* pBool) PURE;
};
I'll write more tomorrow, but this will be part of the #includes...
TTFN
V
ASKER
Looking forward to see more
Ok,
So you have the interface included somewhere...
You can then use something like:
DEFINE_GUID(yatta,yatta,ya tta)
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); // make sure the project has COM/Automation settings, too.
IWebBrowser *pPoint = 0;
CoCreateInstance(CLSID_Bro wser, 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
So you have the interface included somewhere...
You can then use something like:
DEFINE_GUID(yatta,yatta,ya
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); // make sure the project has COM/Automation settings, too.
IWebBrowser *pPoint = 0;
CoCreateInstance(CLSID_Bro
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
ASKER
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.
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.
If you want IE to come up, use IWebBrowserApp. It inherits IWebBrowser.
V
V
ASKER