Monday, March 29, 2010

ISensNetwork based network monitor for Evolution

These weeks I was using my spare cycles to prepare evolution to be buildable and running before the GNOME 2.30 freeze. One of the things that Evolution for windows was missing was an alternative for the NetworkManager network connection detection module. I crafted one using Windows ISensNetwork COM interface. The result is to be found here for those that might be interested in seeing how to implement COM callbacks in plain C.

There are some examples out there showing how to implement ISensNetwork. One of them using heavy ATL framework is to be found here. Another, one, using C++ is to be found here. Both examples have a little problem that actually prevents them from being properly used from unprivileged account, although they work well when Administrator runs them. The problem is that the registering of the event subscription will return E_ACCESSDENIED. Judging from the number of post on different fora when one querries Uncle Google, the solution is not very known. If you have the same problem, please check the plain C example that I crafted using the above-mentioned C++ code as a base. I discovered that specifying that the subscription is a per user one, by using IEventSubscription::put_PerUser(..) method allows your program to register for system events even if it is run as unprivileged user. The source code can be built with different flavours of MinGW and also with Visual Studio and the program installs an icon in the system tray that will notify you when connection status of your computer changes.

By the way, there is not a lot of sample code out there that would use COM from a plain C. Apart excellent code produced by my colleague and object of mute admiration, Tor Lillqvist, there is an wonderful serie of articles by Jeff Glatt. It is worth reading for anybody that wants to do COM the real men's way, in plain C. Here are the links to part 1, part 2, part 3, part 4, part 5, part 6, part 7 and part 8. It is worth to register and get the example code as well as a neat clean html version of the articles. It is enough to download the files linked from the part 8 since they are always cumulated with all files from all previous parts.