.NET wrapper for Webkit
I've created an browser in Visual Studio 2011 with the WebKit .NET wrapper. But since I'm new to C# I maybe have a strange question...
Why ca开发者_如何学JAVAn't I just use: http://www.webkit.org/ for my browser? And if that's impossible, how hard would it be to create an .NET wrapper for WebKit?? And how...
Because Webkit was written in C++, not in C#. A translation layer is needed to marshal between the managed code execution environment of C# and the unmanaged code in Webkit. That's not particularly difficult for Webkit, it supports a COM automation interface. Something that .NET supports well.
The necessary starting point is the type library for Webkit. That's the COM version of assembly metadata, it describes the unmanaged COM interface types in a language neutral manner. The .NET Tlbimp.exe tool translates the type library into a .NET interop library. Easy to do in Visual Studio, you use Project + Add Reference, Browse tab and select the Webkit.tlb file. That automatically generates the Webkit.Interop.dll assembly, the .NET version of the COM interface.
As you might suspect, that interface is not particularly small. From there, you could write friendly .NET wrapper classes that hide the interface complexity, the tack taken by this SourceForge project. Studying it to see how it uses the interface should be enlightening. The .NET WebBrowser control and HtmlDocument and HtmlElement classes work the exact same way, but for IE.
精彩评论