Interopping with VB6 ActiveX windows service
Lately we’ve been re-developing our logging implementation. Basically it comes down to defining a decent interface and implement a component running as a windows service so clients can publish debug and trace information via the push model. One of our main goals is to make a stop to add-hoc logging in files and dumps to the event log. Heck some service engineers didn’t even know the existence of DbMon.exe what basically means nobody ever seriously investigated the art of instrumenting applications.
Where does this all leave me with System.Diagnostics on my shelve? I’m about the only one doing .NET around here!
We decided to craft a VB6 windows service registering itself in the ROT capable of receiving file events. This due to the fact changes to the configuration file (which is XML actually) shouldn’t go un-notified. We don’t want to stop the execution of our main framework in order to reload the configuration (obviously). We now can configure every single component to log to DbMon, event, file, mail whatever with separate categories like information, system error, application error, database error, warning, debug.
This made me decide to skip the Diagnostics API that .NET provides and just interop with the VB6 ActiveX. The trick here is to make sure we’ll receive the unique instance as registered in the ROT. It took some time to figure out that:
LoggingManagerC.cLomCRootClass lmc = (LoggingManagerC.cLomCRootClass) GetObject("","LoggingManagerC.cLomCRoot");
creates a new instance. This did the trick:
LoggingManagerC.cLomCRoot objLoggingService = (LoggingManagerC.cLomCRoot) Marshal.GetActiveObject("LoggingManagerC.cLomCRoot");
I’m now really enthusiastic about .NET’s interoperability. One step further on the path towards .NET acceptance amongst the members of our management team. Is it? Well argh you just never know when it’ll hit them.