COM Fun with Microsoft Agent

Friday, February 25, 2011

Whenever I teach COM interoperability in .NET, I try to show some nice demo for this. The classic is to use one of the Office applications (such as Word) to do some automation by creating a document, adding some text, etc. This is effective enough but not really fun. A much more fun way is to use the Microsoft Agent technology. MS Agent is discontinued as far as further development is concerned, but it’s still fun and great for (at least) learning purposes. What is MS Agent? Its most well known appearance (pun intended) was in the...
one comment

Dealing With Native DLLs in .NET “AnyCPU” Builds

Sunday, February 13, 2011

A .NET application can be compiled using the “AnyCPU” configuration, meaning the application runs as 32 bit on a 32 bit OS, and 64 on a 64 bit OS. As long as the application is purely managed, everything should be just fine. However, if the application must use some native DLL through interop (e.g. P/Invoke), then “AnyCPU” may be an issue. A native DLL cannot be both 32 and 64 bit – it’s one or the other. The traditional solution to the problem is to switch the .NET build to a “Win32” or “x64” configuration, thus aligning...

WPF For WinForms (and MFC) Developers, Part 1

Tuesday, January 11, 2011

WPF has been around for more than 4 years now (since the release of Windows Vista), but only in the last couple of years there is increased move from Windows Forms to WPF. However, the transition is anything but easy. This is not just because WPF is relatively new, or because people are people, and as such don’t like change for the sake of change. I mean, WinForms is ok, isn’t it? MFC may be old, but it works, doesn’t it? The term User Interface (UI) has served us for years. In recent years, this just isn’t enough....

Changing Console Fonts

Thursday, July 23, 2009

The other day I created a Console application and changed some colors and sizes. Then I needed to change the font (programmatically). I looked at the System.Console class – nothing. Maybe they just forgot to wrap it up, I thought, and turned to the Win32 API functions for the Console. Guess what? Nothing. Well, almost nothing. There’s a new function (starting with Vista) called SetCurrentConsoleFontEx, but it’s almost useless. It requires a console font index (which is supposed to be from a console font table, which no documented API reveals), and it doesn’t seem to work quite as expected....

.NET, COM and Apartments Tips

Thursday, February 21, 2008

We all know that when we use COM interop with .NET we get some RCW (Runtime Callable Wrapper) CLR object representing and controlling access to the underlying COM object. When we call the C# new operator, under the hood the RCW calls the CoCreateInstance API to create the actual COM object, etc. What may not be apparent, is that there may exist another proxy to the COM object, even if the COM server is a DLL (in-process server).The reason this may happen is related to COM apartments. an Apartment is a logical container of threads and COM objects that...