.Net Docklet SDK Inner Workings

ObjectDock Docklets are DLL programmed in C or C++ that exports a few callbacks functions. These functions are called when a user manipulate the docklet. Building a docklet in .Net directly is impossible as ObjectDock doesn’t support managed code docklets. Thus, you need some kind of “proxy” that knows about .Net docklets and will be able to interact with them, relaying info to ObjectDock as needed.

Here is a picture that summarize the interactions between the different parts (I know, I could have made an UML Class diagram, but hey, it’s Christmas and I wanted a nice looking picture 😛 )

The Interop Docklet is just a normal docklet that exports all of the possible callbacks functions. Whenever a callback function is called by ObjectDock, the Interop Docklet transmits it to the currently loaded .Net Docklet. The only problem is that you cannot call managed code from unmanaged code directly, you have to use COM to access managed dlls.

Each .Net Docklet should implement the interface IDockletInterface (basically identical to the native docklet callbacks). The Interop docklet knows the GUID of the interface and can create an instance of the .Net Docklet using CoCreateInstance. However, for the call to succeed, the .net docklets have to be registered as COM objects. Asking the user to manually register each plugin with regasm was obviously not an option.

As there is no way (AFAIK) to programmatically register managed COM objects from unmanaged code, the Interop Docklet contains hardcoded info about the DotNetHelper DLL. When the docklet is called for the first time, it write that info in the registry. Then, when a CoCreateInstance call fails, it calls the RegisterDocklets function in DotNetHelper DLL that will walks through the different .Net docklets and try to register them. Problem solved (well almost, but I’ll keep that for another article 🙂 )

The NetDockletHelper DLL also provides the Docklet class that encapsulate SDK functions and keeps the static data associated with each docklet (such as the docklet handle and the different folder paths). Docklet programmer can also use the LOG function from the Util class for debugging purposes.