ExecutionEngineException trying to override IInternetSecurityManager

F

Fredo

I'm going to try to post this without having to paste in hundreds of lines
of code.

I'm trying to override IInternetSecurityManager. I'm taking sort of a
minimalist approach and adding code as I take each step because I'm not 100%
sure about what I'm doing here.

First of all, I've created a WebBrowser class. It is defined as:

public class WebBrowser : AxSHDocVw.AxWebBrowser,
IOleClientSite,
IInternetSecurityManager,
IDocHostUIHandler,
IServiceProvider

The relevant interface definitions are listed at the bottom of this post.
The interface for IDocHostUIHandler comes from MsHtmHstInterop.dll.

Now, for every implementation, I'm doing a Debug.WriteLine() with the method
name so I can see what's getting called.

My QueryService implementation is as follows:

public void QueryService(ref Guid guidService, ref Guid riid, out object
ppvObject)
{
Debug.WriteLine("QueryService");
Guid guid1 = new Guid("79eac9ee-baf9-11ce-8c82-00aa004ba90b");
if (guidService == guid1 &&
riid == guid1)
{
ppvObject = (object) this;
return;
}
ppvObject = null;
throw new COMException("", E_NO_INTERFACE);
}

QueryService gets called a bunch of times, twice matching the
IInternetSecurityManager guid.

The only other two methods called are GetHostInfo and GetOptionKeyPath. Both
methods do:

throw new COMException("", S_OK);

None of the methods in the IInternetSecurityManager interface implementation
get called.

When I call:

_webBrowser.Navigate2(ref page, ref ob, ref ob, ref ob, ref ob);

where page is: "about:blank"

After a number of QueryService calls, the two other calls mentioned, and a
bunch more QueryService calls, the Navigate2 throws a
System.ExecutionEngineException and I'm dead in the water.

Anyone have any ideas? Thanks.


Interface definitions are below:


[ComImport,
Guid("00000118-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleClientSite
{
void SaveObject();
void GetMoniker(uint dwAssign, uint dwWhichMoniker, ref object ppmk);
void GetContainer(ref object ppContainer);
void ShowObject();
void OnShowWindow(bool fShow);
void RequestNewObjectLayout();
}

[ComImport, GuidAttribute("79EAC9EE-BAF9-11CE-8C82-00AA004BA90B")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInternetSecurityManager
{
[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int SetSecuritySite([In] IntPtr pSite);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int GetSecuritySite([Out] IntPtr pSite);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int MapUrlToZone([In,MarshalAs(UnmanagedType.LPWStr)] string pwszUrl,
out UInt32 pdwZone, UInt32 dwFlags);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int GetSecurityId([MarshalAs(UnmanagedType.LPWStr)] string pwszUrl,
[MarshalAs(UnmanagedType.LPArray)] byte[] pbSecurityId,
ref UInt32 pcbSecurityId, uint dwReserved);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int ProcessUrlAction([In,MarshalAs(UnmanagedType.LPWStr)] string
pwszUrl,
UInt32 dwAction, out byte pPolicy, UInt32 cbPolicy,
byte pContext, UInt32 cbContext, UInt32 dwFlags,
UInt32 dwReserved);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int QueryCustomPolicy([In,MarshalAs(UnmanagedType.LPWStr)] string
pwszUrl,
ref Guid guidKey, ref byte ppPolicy, ref UInt32 pcbPolicy,
ref byte pContext, UInt32 cbContext, UInt32 dwReserved);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int SetZoneMapping(UInt32 dwZone,
[In,MarshalAs(UnmanagedType.LPWStr)] string lpszPattern,
UInt32 dwFlags);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int GetZoneMappings(UInt32 dwZone, out UCOMIEnumString ppenumString,
UInt32 dwFlags);
}

[ComImport, GuidAttribute("6D5140C1-7436-11CE-8034-00AA006009FA")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IServiceProvider
{
void QueryService(ref Guid guidService, ref Guid riid,
[MarshalAs(UnmanagedType.Interface)] out object ppvObject);
}
 
F

Fredo

Okay, I came across a posting with something that I tried and it worked
(sort of) and I have absolutely NO idea why.

I changed QueryService from:

void QueryService(ref Guid guidService, ref Guid riid,
[MarshalAs(UnmanagedType.Interface)] out object ppvObject);

to:

void QueryService(ref Guid guidService, ref Guid riid,
[MarshalAs(UnmanagedType.Interface)] out IInternetSecurityManager
ppvObject);


Why would that work? Isn't it just an address at the end of the day?

Okay, so now my app goes much further and all sorts of stuff gets called.
Unfortunately, it dies yet again with a null refrence exception in:

System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop

Anyone have any idea what might be causing that?



Fredo said:
I'm going to try to post this without having to paste in hundreds of lines
of code.

I'm trying to override IInternetSecurityManager. I'm taking sort of a
minimalist approach and adding code as I take each step because I'm not
100% sure about what I'm doing here.

First of all, I've created a WebBrowser class. It is defined as:

public class WebBrowser : AxSHDocVw.AxWebBrowser,
IOleClientSite,
IInternetSecurityManager,
IDocHostUIHandler,
IServiceProvider

The relevant interface definitions are listed at the bottom of this post.
The interface for IDocHostUIHandler comes from MsHtmHstInterop.dll.

Now, for every implementation, I'm doing a Debug.WriteLine() with the
method name so I can see what's getting called.

My QueryService implementation is as follows:

public void QueryService(ref Guid guidService, ref Guid riid, out object
ppvObject)
{
Debug.WriteLine("QueryService");
Guid guid1 = new Guid("79eac9ee-baf9-11ce-8c82-00aa004ba90b");
if (guidService == guid1 &&
riid == guid1)
{
ppvObject = (object) this;
return;
}
ppvObject = null;
throw new COMException("", E_NO_INTERFACE);
}

QueryService gets called a bunch of times, twice matching the
IInternetSecurityManager guid.

The only other two methods called are GetHostInfo and GetOptionKeyPath.
Both methods do:

throw new COMException("", S_OK);

None of the methods in the IInternetSecurityManager interface
implementation get called.

When I call:

_webBrowser.Navigate2(ref page, ref ob, ref ob, ref ob, ref ob);

where page is: "about:blank"

After a number of QueryService calls, the two other calls mentioned, and a
bunch more QueryService calls, the Navigate2 throws a
System.ExecutionEngineException and I'm dead in the water.

Anyone have any ideas? Thanks.


Interface definitions are below:


[ComImport,
Guid("00000118-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleClientSite
{
void SaveObject();
void GetMoniker(uint dwAssign, uint dwWhichMoniker, ref object ppmk);
void GetContainer(ref object ppContainer);
void ShowObject();
void OnShowWindow(bool fShow);
void RequestNewObjectLayout();
}

[ComImport, GuidAttribute("79EAC9EE-BAF9-11CE-8C82-00AA004BA90B")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInternetSecurityManager
{
[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int SetSecuritySite([In] IntPtr pSite);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int GetSecuritySite([Out] IntPtr pSite);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int MapUrlToZone([In,MarshalAs(UnmanagedType.LPWStr)] string pwszUrl,
out UInt32 pdwZone, UInt32 dwFlags);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int GetSecurityId([MarshalAs(UnmanagedType.LPWStr)] string pwszUrl,
[MarshalAs(UnmanagedType.LPArray)] byte[] pbSecurityId,
ref UInt32 pcbSecurityId, uint dwReserved);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int ProcessUrlAction([In,MarshalAs(UnmanagedType.LPWStr)] string
pwszUrl,
UInt32 dwAction, out byte pPolicy, UInt32 cbPolicy,
byte pContext, UInt32 cbContext, UInt32 dwFlags,
UInt32 dwReserved);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int QueryCustomPolicy([In,MarshalAs(UnmanagedType.LPWStr)] string
pwszUrl,
ref Guid guidKey, ref byte ppPolicy, ref UInt32 pcbPolicy,
ref byte pContext, UInt32 cbContext, UInt32 dwReserved);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int SetZoneMapping(UInt32 dwZone,
[In,MarshalAs(UnmanagedType.LPWStr)] string lpszPattern,
UInt32 dwFlags);

[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int GetZoneMappings(UInt32 dwZone, out UCOMIEnumString ppenumString,
UInt32 dwFlags);
}

[ComImport, GuidAttribute("6D5140C1-7436-11CE-8034-00AA006009FA")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IServiceProvider
{
void QueryService(ref Guid guidService, ref Guid riid,
[MarshalAs(UnmanagedType.Interface)] out object ppvObject);
}
 
F

Fredo

Of course, about 3 second after I made that post, I found and fixed the
problem.

I still have one issue remaining which is my ProcessUrlAction is never
called, kind of defeating the purpose of this entire exercise.

Other stuff is getting called in the IInternetSecurityManager interface.

Here's what I get from all my Debug.WriteLines. In the interest of saving
space, wherever QueryService was called multiple times, I've put it in
brackets. Otherwise there'd be about 100 of them. As you can see, though,
GetHostSecurityId is called numerous times, so it's clearly getting to my
IInternetSecurityInterface.

Any ideas?

[QueryService]
GetHostInfo
QueryService
GetOptionKeyPath
[QueryService]
GetSecurityId
[QueryService]
GetSecurityId
[QueryService]
UpdateUI
[QueryService]
HideUI
[QueryService]
TranslateUrl
GetSecurityId
[QueryService]
UpdateUI
[QueryService]
GetSecurityId
GetSecurityId
[QueryService]
GetSecurityId
GetSecurityId
GetSecurityId
GetSecurityId
GetSecurityId
GetHostInfo
[QueryService]
UpdateUI
[QueryService]
GetHostInfo
QueryService
GetOptionKeyPath
[QueryService]
GetSecurityId
[QueryService]
GetSecurityId
[QueryService]
GetSecurityId
GetSecurityId
MapUrlToZone
MapUrlToZone
GetSecurityId
GetSecurityId
[QueryService]
HideUI
[QueryService]
UpdateUI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top