Ok this looks promising. I will go away and experiment with this. It
might take a little while to see what happens with it so bear with me if
I don't reply any time soon.
Success!!! My usercontrol can now access the LocationURL from IE and
determine which protocol to use the access it's file, etc....
Thanks very much to Ying-Shen Yu.
If anyone is interested, I have attached some C++ code which a) wraps
IServiceProvider and IWebBrowser, and b) accesses the IWebBrowser
interface from a usercontrol.
--------------------------------------
a) Wrappers
-----------
namespace MyCorp { namespace IEInterOp {
public __sealed __value class GUIDS
{
private: GUIDS() {}
private: static System::Guid gSID_STopLevelBrowser =
System::Guid("4C96BE40-915C-11CF-99D3-00AA004AE837");
private: static System::Guid gSID_SWebBrowserApp =
System::Guid("0002DF05-0000-0000-C000-000000000046");
public: static System::Guid SID_STopLevelBrowser()
{ return gSID_STopLevelBrowser; }
public: static System::Guid SID_SWebBrowserApp()
{ return gSID_SWebBrowserApp; }
};
[ ComImport,
Guid("6D5140C1-7436-11CE-8034-00AA006009FA"),
InterfaceType(ComInterfaceType::InterfaceIsIUnknown)
]
public __gc __interface IServiceProvider
{
void QueryService(System::Guid* guidService,
System::Guid* riid,
[OutAttribute, MarshalAs(UnmanagedType::IUnknown)]
System::Object** ppvObject);
};
[ ComImport,
Guid("EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B"),
InterfaceType(ComInterfaceType::InterfaceIsIDispatch)
]
public __gc __interface IWebBrowser
{
void GoBack(void);
void GoForward(void);
void GoHome(void);
void GoSearch(void);
void Navigate(System::String* URL,
[MarshalAs(UnmanagedType::Struct)]
System::IntPtr Flags,
[MarshalAs(UnmanagedType::Struct)]
System::IntPtr TargetFrameName,
[MarshalAs(UnmanagedType::Struct)]
System::IntPtr PostData,
[MarshalAs(UnmanagedType::Struct)]
System::IntPtr Headers);
void Refresh(void);
void Refresh2([MarshalAs(UnmanagedType::Struct)]
System::IntPtr Level);
void Stop(void);
[MarshalAs(UnmanagedType::IDispatch)]
__property System::Object* get_Application(void);
[MarshalAs(UnmanagedType::IDispatch)]
__property System::Object* get_Parent(void);
[MarshalAs(UnmanagedType::IDispatch)]
__property System::Object* get_Container(void);
[MarshalAs(UnmanagedType::IDispatch)]
__property System::Object* get_Document(void);
__property bool get_TopLevelContainer(void);
__property System::String* get_Type(void);
__property long get_Left(void);
__property void set_Left(long Left);
__property long get_Top(void);
__property void set_Top(long Top);
__property long get_Width(void);
__property void set_Width(long Width);
__property long get_Height(void);
__property void set_Height(long Height);
__property System::String* get_LocationName(void);
__property System::String* get_LocationURL(void);
__property bool get_Busy(void);
};
-------------------------------
b) code to access the IWebBrowser interface (C++)
void TMyControl:

etermineEnvironment(void)
{
using namespace System::Reflection;
System::Type* thisType = this->GetType();
System::Type* iOleObjectType;
System::Object* oleClientSiteObj;
MyCorp::IEInterOp::IServiceProvider* serviceProvider;
System::Object* topServiceProviderObj;
MyCorp::IEInterOp::IServiceProvider* topServiceProvider;
System::Object* webBrowserObj;
MyCorp::IEInterOp::IWebBrowser* webBrowser;
try
{
iOleObjectType = thisType->GetInterface(S"IOleObject", true);
if (iOleObjectType)
{
using namespace System::Reflection;
oleClientSiteObj = iOleObjectType->InvokeMember(
"GetClientSite",
BindingFlags(BindingFlags::Instance |
BindingFlags::InvokeMethod |
BindingFlags:

ublic),
0, this, 0);
}
if (oleClientSiteObj)
serviceProvider =
dynamic_cast<MyCorp::IEInterOp::IServiceProvider*>(oleClientSiteObj);
if (serviceProvider)
serviceProvider->QueryService(
&MyCorp::IEInterOp::GUIDS::SID_STopLevelBrowser(),
&__typeof(MyCorp::IEInterOp::IServiceProvider)->GUID,
&topServiceProviderObj);
if (topServiceProviderObj)
topServiceProvider =
dynamic_cast<ADI::InterOp::IServiceProvider*>(topServiceProviderObj);
if (topServiceProvider)
topServiceProvider->QueryService(
&MyCorp::IEInterOp::GUIDS::SID_SWebBrowserApp(),
&__typeof(MyCorp::IEInterOp::IWebBrowser)->GUID,
&webBrowserObj);
if (webBrowserObj)
webBrowser =
dynamic_cast<MyCorp::IEInterOp::IWebBrowser*>(webBrowserObj);
if (webBrowser)
{
mHostedByIE = true;
mBaseURL = webBrowser->get_LocationURL();
}
}
__finally
{
using namespace System::Runtime::InteropServices;
if (webBrowser) Marshal::ReleaseComObject(webBrowser);
if (webBrowserObj) Marshal::ReleaseComObject(webBrowserObj);
if (topServiceProvider)
Marshal::ReleaseComObject(topServiceProvider);
if (topServiceProviderObj)
Marshal::ReleaseComObject(topServiceProviderObj);
if (serviceProvider) Marshal::ReleaseComObject(serviceProvider);
if (oleClientSiteObj) Marshal::ReleaseComObject(oleClientSiteObj);
}
}
--
If you wish to reply to me directly, my addres is spam proofed as:
pbromley at adi dot co dot nz
Or if you prefer - (e-mail address removed)
