ExecutionEngineException trying to override IInternetSecurityManager

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fredo

    ExecutionEngineException trying to override IInternetSecurityManager

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

    I'm trying to override IInternetSecuri tyManager. 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.AxWeb Browser,
    IOleClientSite,
    IInternetSecuri tyManager,
    IDocHostUIHandl er,
    IServiceProvide r

    The relevant interface definitions are listed at the bottom of this post.
    The interface for IDocHostUIHandl er 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(re f 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
    IInternetSecuri tyManager guid.

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

    throw new COMException("" , S_OK);

    None of the methods in the IInternetSecuri tyManager interface implementation
    get called.

    When I call:

    _webBrowser.Nav igate2(ref page, ref ob, ref ob, ref ob, ref ob);

    where page is: "about:blan k"

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

    Anyone have any ideas? Thanks.


    Interface definitions are below:


    [ComImport,
    Guid("00000118-0000-0000-C000-000000000046"),
    InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
    public interface IOleClientSite
    {
    void SaveObject();
    void GetMoniker(uint dwAssign, uint dwWhichMoniker, ref object ppmk);
    void GetContainer(re f object ppContainer);
    void ShowObject();
    void OnShowWindow(bo ol fShow);
    void RequestNewObjec tLayout();
    }

    [ComImport, GuidAttribute(" 79EAC9EE-BAF9-11CE-8C82-00AA004BA90B")]
    [InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown)]
    public interface IInternetSecuri tyManager
    {
    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int SetSecuritySite ([In] IntPtr pSite);

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

    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int MapUrlToZone([In,MarshalAs(Un managedType.LPW Str)] string pwszUrl,
    out UInt32 pdwZone, UInt32 dwFlags);

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

    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int ProcessUrlActio n([In,MarshalAs(Un managedType.LPW Str)] string
    pwszUrl,
    UInt32 dwAction, out byte pPolicy, UInt32 cbPolicy,
    byte pContext, UInt32 cbContext, UInt32 dwFlags,
    UInt32 dwReserved);

    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int QueryCustomPoli cy([In,MarshalAs(Un managedType.LPW Str)] string
    pwszUrl,
    ref Guid guidKey, ref byte ppPolicy, ref UInt32 pcbPolicy,
    ref byte pContext, UInt32 cbContext, UInt32 dwReserved);

    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int SetZoneMapping( UInt32 dwZone,
    [In,MarshalAs(Un managedType.LPW Str)] string lpszPattern,
    UInt32 dwFlags);

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

    [ComImport, GuidAttribute(" 6D5140C1-7436-11CE-8034-00AA006009FA")]
    [InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown)]
    public interface IServiceProvide r
    {
    void QueryService(re f Guid guidService, ref Guid riid,
    [MarshalAs(Unman agedType.Interf ace)] out object ppvObject);
    }




  • Fredo

    #2
    Re: ExecutionEngine Exception trying to override IInternetSecuri tyManager

    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(re f Guid guidService, ref Guid riid,
    [MarshalAs(Unman agedType.Interf ace)] out object ppvObject);

    to:

    void QueryService(re f Guid guidService, ref Guid riid,
    [MarshalAs(Unman agedType.Interf ace)] out IInternetSecuri tyManager
    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.Component Manager.System. Windows.Forms.U nsafeNativeMeth ods+IMsoCompone ntManager.FPush MessageLoop

    Anyone have any idea what might be causing that?



    "Fredo" <fredo@hotmail. comwrote in message
    news:S6ednUSGHa E6tbTYnZ2dnUVZ_ oOdnZ2d@giganew s.com...
    I'm going to try to post this without having to paste in hundreds of lines
    of code.
    >
    I'm trying to override IInternetSecuri tyManager. 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.AxWeb Browser,
    IOleClientSite,
    IInternetSecuri tyManager,
    IDocHostUIHandl er,
    IServiceProvide r
    >
    The relevant interface definitions are listed at the bottom of this post.
    The interface for IDocHostUIHandl er 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(re f 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
    IInternetSecuri tyManager guid.
    >
    The only other two methods called are GetHostInfo and GetOptionKeyPat h.
    Both methods do:
    >
    throw new COMException("" , S_OK);
    >
    None of the methods in the IInternetSecuri tyManager interface
    implementation get called.
    >
    When I call:
    >
    _webBrowser.Nav igate2(ref page, ref ob, ref ob, ref ob, ref ob);
    >
    where page is: "about:blan k"
    >
    After a number of QueryService calls, the two other calls mentioned, and a
    bunch more QueryService calls, the Navigate2 throws a
    System.Executio nEngineExceptio n and I'm dead in the water.
    >
    Anyone have any ideas? Thanks.
    >
    >
    Interface definitions are below:
    >
    >
    [ComImport,
    Guid("00000118-0000-0000-C000-000000000046"),
    InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
    public interface IOleClientSite
    {
    void SaveObject();
    void GetMoniker(uint dwAssign, uint dwWhichMoniker, ref object ppmk);
    void GetContainer(re f object ppContainer);
    void ShowObject();
    void OnShowWindow(bo ol fShow);
    void RequestNewObjec tLayout();
    }
    >
    [ComImport, GuidAttribute(" 79EAC9EE-BAF9-11CE-8C82-00AA004BA90B")]
    [InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown)]
    public interface IInternetSecuri tyManager
    {
    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int SetSecuritySite ([In] IntPtr pSite);
    >
    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int GetSecuritySite ([Out] IntPtr pSite);
    >
    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int MapUrlToZone([In,MarshalAs(Un managedType.LPW Str)] string pwszUrl,
    out UInt32 pdwZone, UInt32 dwFlags);
    >
    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int GetSecurityId([MarshalAs(Unman agedType.LPWStr )] string pwszUrl,
    [MarshalAs(Unman agedType.LPArra y)] byte[] pbSecurityId,
    ref UInt32 pcbSecurityId, uint dwReserved);
    >
    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int ProcessUrlActio n([In,MarshalAs(Un managedType.LPW Str)] string
    pwszUrl,
    UInt32 dwAction, out byte pPolicy, UInt32 cbPolicy,
    byte pContext, UInt32 cbContext, UInt32 dwFlags,
    UInt32 dwReserved);
    >
    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int QueryCustomPoli cy([In,MarshalAs(Un managedType.LPW Str)] string
    pwszUrl,
    ref Guid guidKey, ref byte ppPolicy, ref UInt32 pcbPolicy,
    ref byte pContext, UInt32 cbContext, UInt32 dwReserved);
    >
    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int SetZoneMapping( UInt32 dwZone,
    [In,MarshalAs(Un managedType.LPW Str)] string lpszPattern,
    UInt32 dwFlags);
    >
    [return: MarshalAs(Unman agedType.I4)][PreserveSig]
    int GetZoneMappings (UInt32 dwZone, out UCOMIEnumString ppenumString,
    UInt32 dwFlags);
    }
    >
    [ComImport, GuidAttribute(" 6D5140C1-7436-11CE-8034-00AA006009FA")]
    [InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown)]
    public interface IServiceProvide r
    {
    void QueryService(re f Guid guidService, ref Guid riid,
    [MarshalAs(Unman agedType.Interf ace)] out object ppvObject);
    }
    >
    >
    >
    >

    Comment

    • Fredo

      #3
      Re: ExecutionEngine Exception trying to override IInternetSecuri tyManager

      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 ProcessUrlActio n is never
      called, kind of defeating the purpose of this entire exercise.

      Other stuff is getting called in the IInternetSecuri tyManager interface.

      Here's what I get from all my Debug.WriteLine s. 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,
      GetHostSecurity Id is called numerous times, so it's clearly getting to my
      IInternetSecuri tyInterface.

      Any ideas?

      [QueryService]
      GetHostInfo
      QueryService
      GetOptionKeyPat h
      [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
      GetOptionKeyPat h
      [QueryService]
      GetSecurityId
      [QueryService]
      GetSecurityId
      [QueryService]
      GetSecurityId
      GetSecurityId
      MapUrlToZone
      MapUrlToZone
      GetSecurityId
      GetSecurityId
      [QueryService]
      HideUI
      [QueryService]
      UpdateUI


      Comment

      Working...