maybeleo

Hi.

I'v initially posted this into .NET Development / CLR, but here it seems to be more suitable, so I would like to repeat my question.

Well, I have implemented a couple of asynchronous pluggable protocols (in C#) for IE. They are registered as temporary namespace handlers and used with WebBrowser controls in my WinForms project. All works fine until WebBrowser.ShowPrintPreviewDialog() is called. Then, during next garbage collection (started by GC itself or invoked by GC.Collect()), the DisconnectedContext MDA is activated while debugging or, if application runs separately from debugger, there SEHExceptions or something like are thrown. Sometimes in this case an application can simply hang (stop responding on keyboard and mouse input) without any exceptions. So what is the workaround for that

The entry point method of an application is marked with STAThread attribute (otherwise WebBrowser control cannot be instantiated), and creation and usage of my objects that implement pluggable protocols proceed in the same thread, of course, the main (GUI) thread. But I'v noticed that Print Preview Dialog shown by ShowPrintPreviewDialog() uses its own thread and operates with my pluggable protocol handlers in that thread. Could it be the core of a problem, and if so, how can I fix that



Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

Ophir G

Hi,

Although I am not answering your question at all, I was wondering if you were able to successfully develop an APP by implementing the IInternetProtocol interface, or just using the .NET's RegisterNameSpcae method.

Thanks,

Ophir.





Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

maybeleo

Ophir,

there are no any difficulties, actually. Yes, I¡¯ve just implemented IInternetProtocol (and IInternetProtocolRoot, of course) and IInternetProtocolInfo. Since all I needed were temporary namespace handlers (used only in concrete instance of my application), I¡¯ve used RegistrationServices.RegisterAssembly() to add to registry info required by COM to instantiate objects (in fact, links to mscoree.dll) on application startup and UnregisterAssembly() at shutdown. Next, the DllGetClassObject() function has been imported from mscoree.dll to get pointer to class factory (provided by mscoree.dll) and then pass this pointer to IInternetSession.RegisterNameSpace(). An IInternetSession pointer can be obtained via CoInternetGetSession(). This works and one can find many similar implementations of APP across the internet. But problems start rising when managed implementations of APPs used in multithreading environment, for example, when using WebBrowser.ShowPrintPreviewDialog() (print preview window has its own gui thread)...





Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

Ophir G

Hello again maybeleo,

Thank you for your response. Since I have read you post, I have been trying to implement this myself. However, I am still ecountering some problems. I also looked across the web trying to find some code example, but still - no luck. I would appreciate it if you could post some code for me to see, or even post a link that I can follow regarding that subject.

Thanks in advance.





Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

maybeleo

Hi, Ophir G!

Here http://ultrashare.net/hosting/fl/5b0e6e424c you can find an archive with a couple of source files. This is a simple abstract class named IeApp that implements basic functionality of IE APPs. All you need is to write your descendant, mark it with [Guid(your_newly_generated_guid), ComVisible(true)], and override two abstract members - ProcessRequest() and Scheme. This implementation assumes your protocol needs not much time to reply on request. Here is simple example:

Code Snippet

using System;

using System.Runtime.InteropServices;

using ArtSko.Tools.IeApps;

namespace ClassLibrary1

{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("B971A539-E5AC-4e58-855F-349DC158C038")]
public class Class3 : IeApp
{
protected override void ProcessRequest(ref int result, out byte[] data)
{
HeaderResult(result);
HeaderContentType(KnownContentType.TextHtml, true);
data = ContentEncoding.GetBytes(Resource1.MultiPage.Replace("", Uri.UnescapeDataString(RequestedUrl.Query.Remove(0, 1))));
HeaderContentLength(data.Length);
HeaderConnectionClosed();
}

protected override string Scheme { get { return "printemplate"; } }
}

}

In this example an URL like printemplate:/// sometemplate is passed (this is not shown here) to IOleCommandTarget.Exec() and then handled by my pluggable protocol (implemented by Class3) which just loads some template from resources and returns it to IE. Of course, APPs need registration. Since it's just temporary protocol handler, you may use something like this in your WinForms application:

Code Snippet

static Form1()

{

IeApp.RegisterHandlerAssembly(typeof(Class3).Assembly, true); // Class3 must be declared in separate library (dll) project!

IeApp.RegisterTemporaryHandler<Class3>(true);

Application.ApplicationExit += delegate(object sender, EventArgs e)

{

IeApp.RegisterTemporaryHandler<Class3>(false); // you may omit this

IeApp.RegisterHandlerAssembly(typeof(Class3).Assembly, false);

};

}

Now, for any instance of WebBrowser control used in your application a new printemplate:// protocol is available. Good luck!





Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

Ophir G

Hello again maybeleo,

I want to thank you for sending your code and explaining so well. However, I tried using your solution for intercepting HTTP requests and send them myself, using the HttpWebRequets class and it did not work. Unfortunately, it seems that it is an impossible thing to do with the current interoperability architecture.

I want to thank you again for replying my messages.

Ophir.





Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

maybeleo

Yes, pure .NET architecture named "pluggable protocols" based on WebRequest and WebResponse descendants has nothing common with IE asynchronous pluggable protocols, they are absolutely different and independent things. Probably you've been misled by similar names of those technologies. If you need your own web protocol for your application, you have to use WebRequest and WebResponse. If you want to present the content in WebBrowser (IE) with some non-typical processing - you have to implement APP for IE.





Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

Ophir G

You are right. However, trying to implement APP for IE (or a WebBrowser control) resulted a very buggy application providing many crashes.

You can read more here:

http://groups.google.com/group/microsoft.public.inetsdk.programming.webbrowser_ctl/browse_thread/thread/3b1aa8af584af95b/a91685515f68aa09 hl=en#a91685515f68aa09

Ophir.





Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

maybeleo

Hmmm... As for me, I didn't encounter such serious problems - the problems I've written about were eventually solved by simple workaround - by avoiding of IE print preview usage (so only one thread accessed my APPs)... Would you like to describe the schema of your IE APP implementation, maybe I could do something with it.



Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

RatneshK

hey maybeleo,

I am not able to access "http://ultrashare.net/hosting/fl/5b0e6e424c" , where you posted your legendary .Net code for APP. Please upload it again if possible.
Waiting for you response.
thanks in advance




Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

maybeleo

Hi, RatneshK!

That code is far from being legendary

As for uploading - right now I've checked link I posted and it's all ok with it. So if you give me some link to another file-exchange site or maybe some e-mail where to post code then I, of course, will do it.




Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

novikov

Thanks for useful code!

Is any possibility exists to use native Http/Https handlers inside of custom handlers

For now we need to implement method ProcessRequest of IeApp where all data loads. But this method blocks WebBrowser till data loaded. So, my intention is to use native handlers wrapped into my custom handler where url and request/responce headers go through some kind of filter.

Does you faced with issue like this




Re: Internet Explorer Extension Development .NET 2.0: WebBrowser, Asynchronous pluggable protocols and DisconnectedContext MDA

maybeleo

Yes, as I wrote above, this is very basic implementation and assumes that request processing doesn't require significant time. If you need some other scenario, you should refer to the description of IInternetProtocolRoot.Start in msdn. There stated that you can return E_PENDING to indicate that operation started but will complete asynchronously. You should also make some experiments with IInternetProtocolSink.ReportData method to indicate urlmon.dll your progress and state. As for using standard handlers - sorry, I didn't dig this issue deeply. The only thing I know that permanent handlers are registered under HKEY_CLASSES_ROOT\PROTOCOLS\Handler. You probably can obtain clsid for http, for example, and create standard handler with Activator.CreateInstance(Type.GetGetTypeFromCLSID(Guid clsid)), and then use it inside your pluggable handler.

P.S. Here is description of APPs. Plus a lot of experiments from your side