<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Richard Cook</title><subtitle type="html">How VSTO will change your life (for the better, that is)</subtitle><id>http://blogs.msdn.com/rcook/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/rcook/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2008-10-11T23:35:00Z</updated><entry><title>Issues with Office 2007 PIA redist and ComponentCheck.exe</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2009/03/12/issues-with-office-2007-pia-redist-and-componentcheck-exe.aspx" /><id>http://blogs.msdn.com/rcook/archive/2009/03/12/issues-with-office-2007-pia-redist-and-componentcheck-exe.aspx</id><published>2009-03-12T20:14:00Z</published><updated>2009-03-12T20:14:00Z</updated><content type="html">A number of people (see this and this for starters) have reported weird behaviour with ComponentCheck.exe which is used as the prerequisite checker for the VSTO Office 2007 PIA redistributable package that was added in Visual Studio 2008 SP1. For those of you unfamiliar with how the setup.exe is created when an add-in is published, it may come as a surprise to learn that ComponentCheck.exe ends up being embedded directly into setup.exe . When setup.exe is run on the target machine, ComponentCheck.exe...(&lt;a href="http://blogs.msdn.com/rcook/archive/2009/03/12/issues-with-office-2007-pia-redist-and-componentcheck-exe.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9471945" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term="Office" scheme="http://blogs.msdn.com/rcook/archive/tags/Office/default.aspx" /><category term="VSTO" scheme="http://blogs.msdn.com/rcook/archive/tags/VSTO/default.aspx" /></entry><entry><title>VSTO runtime compatibility</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2009/02/24/vsto-runtime-compatibility.aspx" /><id>http://blogs.msdn.com/rcook/archive/2009/02/24/vsto-runtime-compatibility.aspx</id><published>2009-02-24T20:43:00Z</published><updated>2009-02-24T20:43:00Z</updated><content type="html">&lt;P&gt;Some items on VSTO compatibility including my own &lt;EM&gt;compatibility matrix&lt;/EM&gt;:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/rcook/pages/visual-studio-tools-for-office-versioning-and-compatibility.aspx" mce_href="http://blogs.msdn.com/rcook/pages/visual-studio-tools-for-office-versioning-and-compatibility.aspx"&gt;My article on the subject&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb608603.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb608603.aspx"&gt;A MSDN article on this subject&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms178739.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms178739.aspx"&gt;Another MSDN article on related subject matter&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9442930" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term="VSTO" scheme="http://blogs.msdn.com/rcook/archive/tags/VSTO/default.aspx" /></entry><entry><title>What have I been up to?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2009/01/29/what-have-i-been-up-to.aspx" /><id>http://blogs.msdn.com/rcook/archive/2009/01/29/what-have-i-been-up-to.aspx</id><published>2009-01-29T23:31:00Z</published><updated>2009-01-29T23:31:00Z</updated><content type="html">&lt;P&gt;Well, first of all I started as a part-time graduate student at the University of Washington in the &lt;A class="" href="http://pmp.cs.washington.edu/" mce_href="http://pmp.cs.washington.edu/"&gt;Professional Master's Program&lt;/A&gt;&amp;nbsp;in computer science and engineering. This is very exciting and I'm learning a lot of interesting things particularly in the areas of &lt;A class="" href="http://www.cs.washington.edu/education/courses/csep505/" mce_href="http://www.cs.washington.edu/education/courses/csep505/"&gt;functional programming languages&lt;/A&gt; (as you may have figured given my previous references to F# and OCaml) and &lt;A class="" href="http://www.cs.washington.edu/education/courses/csep531/" mce_href="http://www.cs.washington.edu/education/courses/csep531/"&gt;complexity theory&lt;/A&gt;. I've also signed up for &lt;A class="" href="http://seattle2.startupweekend.com/" mce_href="http://seattle2.startupweekend.com/"&gt;Seattle Startup Weekend 2&lt;/A&gt;&amp;nbsp;which I should definitely plug since &lt;A class="" href="http://www.microsoft.com/" mce_href="http://www.microsoft.com/"&gt;Microsoft&lt;/A&gt; is the national sponsor. That's next weekend and I'm really looking forward to it.&lt;/P&gt;
&lt;P&gt;What else? Well, in parallel with this, my MSDN blog, I've also started working on my &lt;A class="" href="http://www.opiumtrail.com/" mce_href="http://www.opiumtrail.com/"&gt;personal blog&lt;/A&gt;. This I decided to keep separate since the main subject of my posts on this site, while still primarily of a technical nature, mainly revolve around the interesting challenges associated with writing the actual &lt;EM&gt;blog&lt;/EM&gt; code from scratch. So there.&lt;/P&gt;
&lt;P&gt;Anyway, I do plan to post here more often soon.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9383634" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term="University of Washington" scheme="http://blogs.msdn.com/rcook/archive/tags/University+of+Washington/default.aspx" /><category term="Seattle Startup Weekend" scheme="http://blogs.msdn.com/rcook/archive/tags/Seattle+Startup+Weekend/default.aspx" /></entry><entry><title>OCaml and F#</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/12/02/ocaml-and-f.aspx" /><id>http://blogs.msdn.com/rcook/archive/2008/12/02/ocaml-and-f.aspx</id><published>2008-12-02T07:16:00Z</published><updated>2008-12-02T07:16:00Z</updated><content type="html">So, I decided that Objective-C is not that interesting for the time being. I thought I'd play with &lt;A href="http://research.microsoft.com/fsharp/" target=_blank mce_href="http://research.microsoft.com/fsharp/"&gt;F#&lt;/A&gt; instead. More on this later…&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9162998" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author></entry><entry><title>Languages: Objective-C this time</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/11/19/languages-objective-c-this-time.aspx" /><id>http://blogs.msdn.com/rcook/archive/2008/11/19/languages-objective-c-this-time.aspx</id><published>2008-11-19T12:31:00Z</published><updated>2008-11-19T12:31:00Z</updated><content type="html">&lt;p&gt;
I switched on my Mac for the first time in about three months this evening. I had a hankering to do some Objective-C. This is a language I've tried to master before but without huge amounts of success. However, with my renewed interest in late binding and dynamic languages, I think it's time to start looking again. And this time it's absolutely going to happen. Before I switched on the Mac I tried the &lt;a href="http://users.telenet.be/stes/compiler.html" target="_blank" mce_href="http://users.telenet.be/stes/compiler.html"&gt;Portable Object Compiler&lt;/a&gt; and &lt;a href="http://www.mingw.org/" target="_blank" mce_href="http://www.mingw.org/"&gt;MinGW&lt;/a&gt; port of GCC on my Windows box but couldn't get either of them to compile my sources without the compiler crashing due to segmentation faults (caused by exception handling, I believe). Not cool. Anyway, I'm back in Mac land and having fun.
&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9123320" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term="Dynamic programming" scheme="http://blogs.msdn.com/rcook/archive/tags/Dynamic+programming/default.aspx" /><category term="Objective-C" scheme="http://blogs.msdn.com/rcook/archive/tags/Objective-C/default.aspx" /><category term="Late binding" scheme="http://blogs.msdn.com/rcook/archive/tags/Late+binding/default.aspx" /></entry><entry><title>Multimethods in C# revisited</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/11/12/multimethods-in-c-revisited.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="19091" href="http://blogs.msdn.com/rcook/attachment/9061441.ashx" /><id>http://blogs.msdn.com/rcook/archive/2008/11/12/multimethods-in-c-revisited.aspx</id><published>2008-11-12T09:11:00Z</published><updated>2008-11-12T09:11:00Z</updated><content type="html">&lt;P&gt;So I thought long and hard about my initial stab at a multimethod implementation for C#. It was a reasonable proof of concept. However, I read some more on the subject of multiple dispatch and the visitor pattern and came up with a few additional ideas. These are encapsulated in the attached project. I have also reproduced the &lt;A href="http://blogs.msdn.com/rcook/pages/multimethods-in-c-revisited-multimethodfactory-cs.aspx" target=_blank mce_href="http://blogs.msdn.com/rcook/pages/multimethods-in-c-revisited-multimethodfactory-cs.aspx"&gt;main source file&lt;/A&gt; since this is where most of the action takes place.&lt;/P&gt;
&lt;P&gt;This was, for me, an interesting digression into the area of IL generation using &lt;TT&gt;System.Reflection.Emit&lt;/TT&gt; which is something I haven't done since my old &lt;A href="http://www.microsoft.com/speech/" target=_blank mce_href="http://www.microsoft.com/speech/"&gt;Speech Server&lt;/A&gt; days.&lt;/P&gt;
&lt;P&gt;Here's a summary of what I ended up doing:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The &lt;A href="http://blogs.msdn.com/rcook/pages/multimethods-in-c-revisited-multimethodfactory-cs.aspx" target=_blank mce_href="http://blogs.msdn.com/rcook/pages/multimethods-in-c-revisited-multimethodfactory-cs.aspx"&gt;multimethod factory&lt;/A&gt; generates a dynamic assembly on the fly. This assembly contains an automatically generated holder class encapsulating the delegate corresponding to each runtime overload of the multimethod plus a private invoker method for each overload. A central invoker method uses &lt;TT&gt;System.Type.InvokeMember&lt;/TT&gt; to perform runtime method resolution while the private invokers perform marshalling and unmarshalling of arguments in and out of the runtime overload.&lt;/LI&gt;
&lt;LI&gt;This implementation supports by-reference arguments such as &lt;TT&gt;ref&lt;/TT&gt; and &lt;TT&gt;out&lt;/TT&gt; parameters along with &lt;TT&gt;in&lt;/TT&gt; parameters as well as return values, so it offers something much closer to a complete solution than my initial implementation.&lt;/LI&gt;
&lt;LI&gt;The &lt;TT&gt;DebugInfo&lt;/TT&gt; configuration class can be used to force the code generation phase to generate on-disc assemblies, symbols and pseudo-code which is provided to aid debugging of the generated IL: the code generation is somewhat fragile and it's very easy to leave the code generating "invalid program" errors when it gets JITted.&lt;/LI&gt;
&lt;LI&gt;The on-disc assemblies can also be referenced in other solutions in order to use the generated multimethod without the overhead of the code/assembly generation phase.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;For future investigation:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;It would be nice to eliminate the reflection. As discussed at the recent &lt;A href="http://channel9.msdn.com/pdc2008/TL16/" target=_blank mce_href="http://channel9.msdn.com/pdc2008/TL16/"&gt;PDC&lt;/A&gt;, there is a new planned &lt;TT&gt;dynamic&lt;/TT&gt; pseudo-type in C# 4.0 which will allow for late-bound method calls. This is designed to improve COM interoperability but could just as well be applied to the problem of multiple dispatch. It would likely simplify a great deal of the IL that my multimethod factory has to generate.&lt;/LI&gt;
&lt;LI&gt;Currently, the delegate types used to construct the multimethod have to be declared &lt;TT&gt;public&lt;/TT&gt; since the dynamic assembly that implements the multimethod holder needs to be able to access these types at runtime. I would like to be able to remove this limitation in order to improve encapsulation.&lt;/LI&gt;
&lt;LI&gt;I'm sure I could use abstract syntax trees and DLR-type on-the-fly code generation to do much of what can be done here. However, to remain compatible with .NET Framework 3.5 I'll be sticking with my reflection-based implementation for the time being!&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Until next time…&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9061441" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term=".NET" scheme="http://blogs.msdn.com/rcook/archive/tags/.NET/default.aspx" /><category term="C#" scheme="http://blogs.msdn.com/rcook/archive/tags/C_2300_/default.aspx" /><category term="Dynamic programming" scheme="http://blogs.msdn.com/rcook/archive/tags/Dynamic+programming/default.aspx" /><category term="Speech Server" scheme="http://blogs.msdn.com/rcook/archive/tags/Speech+Server/default.aspx" /></entry><entry><title>Multimethods in C#</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/11/11/multimethods-in-c.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="7536" href="http://blogs.msdn.com/rcook/attachment/9059252.ashx" /><id>http://blogs.msdn.com/rcook/archive/2008/11/11/multimethods-in-c.aspx</id><published>2008-11-11T07:25:00Z</published><updated>2008-11-11T07:25:00Z</updated><content type="html">&lt;P&gt;I read a couple of interesting articles on the subject of &lt;A class="" href="http://en.wikipedia.org/wiki/Multiple_dispatch" mce_href="http://en.wikipedia.org/wiki/Multiple_dispatch"&gt;multiple dispatch&lt;/A&gt; last night. The first, entitled &lt;A class="" href="http://nice.sourceforge.net/visitor.html" mce_href="http://nice.sourceforge.net/visitor.html"&gt;Visitor Pattern Considered Useless&lt;/A&gt;, starts by describing the visitor design pattern with particular emphasis on how it can enable the definition of new operations on a hierarchy of types without having to modify the hierarchy's classes themselves. It gave a quick overview and then moved on to a critique of the pattern and segued into a description of the multimethod implementation provided by &lt;A class="" href="http://nice.sourceforge.net/index.html" mce_href="http://nice.sourceforge.net/index.html"&gt;Nice&lt;/A&gt; which is a very interesting Java-like (and hence C#-like) object-oriented programming language. This got me thinking about playing around with the idea of multiple dispatch in C#. Check out the &lt;A class="" href="http://blogs.msdn.com/rcook/attachment/9059252.ashx" mce_href="http://blogs.msdn.com/rcook/attachment/9059252.ashx"&gt;attachment&lt;/A&gt; containing a sample project I hacked together or &lt;A class="" href="http://blogs.msdn.com/rcook/pages/multiple-dispatch-in-c-multimethodfactory-class.aspx" mce_href="http://blogs.msdn.com/rcook/pages/multiple-dispatch-in-c-multimethodfactory-class.aspx"&gt;view the main class&amp;nbsp;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Note the following:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Basically, it performs overload resolution of generic methods at &lt;EM&gt;runtime&lt;/EM&gt; as opposed to C#'s usual overload resolution which is performed at compile time.&lt;/LI&gt;
&lt;LI&gt;It's based heavily around delegates.&lt;/LI&gt;
&lt;LI&gt;It determines the "most compatible" method based on a measure of "generality" of parameter types compared to actual argument types.&lt;/LI&gt;
&lt;LI&gt;Currently it only handles methods that take "in" parameters. It doesn't do "out" or "ref" and doesn't support return values yet.&lt;/LI&gt;
&lt;LI&gt;The code is not performant: currently all the runtime overload resolution is done through multiple "for" loops over the parameter and argument type arrays. I'm sure some DLR-type magic could be employed instead to improve the performance of this area of the code.&lt;/LI&gt;
&lt;LI&gt;This code is incredibly rough around the edges.&lt;/LI&gt;
&lt;LI&gt;It's a work in progress.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;If there are any other dynamic programmers in C# interested in this kind of thing, then let me know!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9059252" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term=".NET" scheme="http://blogs.msdn.com/rcook/archive/tags/.NET/default.aspx" /><category term="Code" scheme="http://blogs.msdn.com/rcook/archive/tags/Code/default.aspx" /><category term="C#" scheme="http://blogs.msdn.com/rcook/archive/tags/C_2300_/default.aspx" /><category term="Dynamic programming" scheme="http://blogs.msdn.com/rcook/archive/tags/Dynamic+programming/default.aspx" /><category term="Nice" scheme="http://blogs.msdn.com/rcook/archive/tags/Nice/default.aspx" /></entry><entry><title>Dump out all installed products and components</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/11/09/dump-out-all-installed-products-and-components.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="5322" href="http://blogs.msdn.com/rcook/attachment/9055403.ashx" /><id>http://blogs.msdn.com/rcook/archive/2008/11/09/dump-out-all-installed-products-and-components.aspx</id><published>2008-11-09T12:01:00Z</published><updated>2008-11-09T12:01:00Z</updated><content type="html">&lt;P&gt;Windows Installer APIs tamed in managed code: use this to dump out a list of all installed product codes and component IDs. Quick and easy. Good night everybody!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9055403" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term=".NET" scheme="http://blogs.msdn.com/rcook/archive/tags/.NET/default.aspx" /><category term="Code" scheme="http://blogs.msdn.com/rcook/archive/tags/Code/default.aspx" /><category term="Windows programming" scheme="http://blogs.msdn.com/rcook/archive/tags/Windows+programming/default.aspx" /><category term="C#" scheme="http://blogs.msdn.com/rcook/archive/tags/C_2300_/default.aspx" /></entry><entry><title>STL functors, scoped handles and how we can use them in Windows programming</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/11/04/stl-functors-scoped-handles-and-how-we-can-use-them-in-windows-programming.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="5574" href="http://blogs.msdn.com/rcook/attachment/9039941.ashx" /><id>http://blogs.msdn.com/rcook/archive/2008/11/04/stl-functors-scoped-handles-and-how-we-can-use-them-in-windows-programming.aspx</id><published>2008-11-04T18:39:00Z</published><updated>2008-11-04T18:39:00Z</updated><content type="html">&lt;P&gt;Firstly, it's election day so get out there and vote! Secondly, I went to bed last night and dreamt about functors! Last Friday I code-reviewed some changes made by one of my colleagues and his code just happened to use some STL containers and all sorts of related goodies. The last time I tried to use STL was about eight years ago when I was still at college and, admittedly, I didn't use them much: compiler support (both on Unix and Windows platforms) was not great and so I ended up using Matlab for most of my work instead.&lt;/P&gt;
&lt;P&gt;Anyway, this got me thinking: wouldn't it be nice to be able to use the STL &lt;TT&gt;auto_ptr&lt;/TT&gt; template to manage Windows handles in addition to regular old object pointers? Unfortunately, this was a no-go for two main reasons:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The semantics are all wrong: &lt;TT&gt;auto_ptr&amp;lt;HANDLE&amp;gt;&lt;/TT&gt;, where &lt;TT&gt;HANDLE&lt;/TT&gt; is a generic Windows-style opaque pointer, doesn't work as the resulting &lt;TT&gt;auto_ptr&lt;/TT&gt; specialization is semantically equivalent to &lt;TT&gt;HANDLE *&lt;/TT&gt; (i.e. a pointer to a &lt;TT&gt;HANDLE&lt;/TT&gt;). This is one level of pointer indirection too much to be useful for us.&lt;/LI&gt;
&lt;LI&gt;&lt;TT&gt;auto_ptr&lt;/TT&gt;, unlike the TR1 &lt;TT&gt;shared_ptr&lt;/TT&gt;, does not allow the developer to define a custom deleter function: &lt;TT&gt;auto_ptr&lt;/TT&gt; always invokes the &lt;TT&gt;delete&lt;/TT&gt; operator on the type of the encapsulated pointer. Windows handles typically use &lt;TT&gt;CloseHandle&lt;/TT&gt; or something similar.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;So, I began to write my own. First, I thought I'd steal some inspiration from the &lt;TT&gt;auto_ptr&lt;/TT&gt; and &lt;TT&gt;shared_ptr&lt;/TT&gt; classes. Unfortunately, this is not easy as it might sound. Anybody who has ever read the source code for STL would likely agree with me on this: the STL headers are not designed to be humanly readable as far as I can tell. Therefore I had to write it from scratch and reproduced below is my &lt;TT&gt;scoped_handle&lt;/TT&gt; implementation:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/rcook/pages/stl-functors-scoped-handles-and-how-we-can-use-them-in-windows-programming-scoped-handle.aspx" target=_blank mce_href="http://blogs.msdn.com/rcook/pages/stl-functors-scoped-handles-and-how-we-can-use-them-in-windows-programming-scoped-handle.aspx"&gt;Click to view source code for &lt;TT&gt;scoped_handle&lt;/TT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Of course, I went through several iterations before I got it right. The first used a single encapsulated deleter function pointer. This suffered from the main issue that the deleter function had to conform to a very specific function prototype. Thus it becomes difficult to produce a generic class that can handle &lt;TT&gt;void (*)(HANDLE)&lt;/TT&gt; functions and &lt;TT&gt;BOOL (*)(HANDLE)&lt;/TT&gt; equally well (&lt;TT&gt;CloseHandle&lt;/TT&gt; belonging to the latter category). After some head scratching I developed the implementation listed above based on the STL-style concept of functors. Specifically, this template class can handle any object, be it a function or class or anything else, as long as it supplies an overload of &lt;TT&gt;operator()&lt;/TT&gt; that takes a single appropriately typed argument. This operator can return any type since &lt;TT&gt;scoped_handler&lt;/TT&gt; ignores the return value anyway.&lt;/P&gt;
&lt;P&gt;A few caveats become obvious:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Beware compiler warning &lt;A href="http://msdn.microsoft.com/en-us/library/4ddd21xh.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/4ddd21xh.aspx"&gt;C4930&lt;/A&gt; from Visual C++! This warning is the reason why I did not provide a constructor of the form &lt;TT&gt;explicit scoped_handle(CALLABLE_TYPE)&lt;/TT&gt; which would have created a default, "empty" handle set to &lt;TT&gt;UNDEFINED_VALUE&lt;/TT&gt; initialized with the specified deleter. The compiler cannot distinguish between a class instantation or function prototype in this type of code.&lt;/LI&gt;
&lt;LI&gt;This code throws C++-style exceptions. If you're using this class in COM code you must catch all C++ exceptions and translate them into equivalent &lt;TT&gt;HRESULT&lt;/TT&gt;s or stack-unwinding chaos will ensue.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;This is roughly how one might use the &lt;TT&gt;scoped_handle&lt;/TT&gt; class in conjunction with common Windows APIs:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/rcook/pages/stl-functors-scoped-handles-and-how-we-can-use-them-in-windows-programming-example-of-usage.aspx" target=_blank mce_href="http://blogs.msdn.com/rcook/pages/stl-functors-scoped-handles-and-how-we-can-use-them-in-windows-programming-example-of-usage.aspx"&gt;Click to view source code for example of usage&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;See you next time!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9039941" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term="C++" scheme="http://blogs.msdn.com/rcook/archive/tags/C_2B002B00_/default.aspx" /><category term="STL" scheme="http://blogs.msdn.com/rcook/archive/tags/STL/default.aspx" /><category term="Windows programming" scheme="http://blogs.msdn.com/rcook/archive/tags/Windows+programming/default.aspx" /></entry><entry><title>Posted updated version of IConnectionPoint article</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/10/30/posted-updated-version-of-iconnectionpoint-article.aspx" /><id>http://blogs.msdn.com/rcook/archive/2008/10/30/posted-updated-version-of-iconnectionpoint-article.aspx</id><published>2008-10-30T09:14:00Z</published><updated>2008-10-30T09:14:00Z</updated><content type="html">So, I did a whole lot more research and investigation of COM eventing in Office applications and how this compares to the "general" COM eventing case. Check out &lt;A class="" href="http://blogs.msdn.com/rcook/pages/iconnectionpoint-and-net-or-how-i-learned-to-stop-worrying-and-love-managed-event-sinks-part-1.aspx" mce_href="http://blogs.msdn.com/rcook/pages/iconnectionpoint-and-net-or-how-i-learned-to-stop-worrying-and-love-managed-event-sinks-part-1.aspx"&gt;IConnectionPoint and .NET or: How I Learned to Stop Worrying and Love Managed Event Sinks (part 1)&lt;/A&gt;.&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9023752" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term="PIAs" scheme="http://blogs.msdn.com/rcook/archive/tags/PIAs/default.aspx" /><category term="Excel" scheme="http://blogs.msdn.com/rcook/archive/tags/Excel/default.aspx" /><category term="Office" scheme="http://blogs.msdn.com/rcook/archive/tags/Office/default.aspx" /><category term="COM" scheme="http://blogs.msdn.com/rcook/archive/tags/COM/default.aspx" /><category term=".NET" scheme="http://blogs.msdn.com/rcook/archive/tags/.NET/default.aspx" /><category term="VSTO" scheme="http://blogs.msdn.com/rcook/archive/tags/VSTO/default.aspx" /></entry><entry><title>My first article had a few mistakes in it...</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/10/18/my-first-article-has-a-few-mistakes-and-inaccuracies-in-it.aspx" /><id>http://blogs.msdn.com/rcook/archive/2008/10/18/my-first-article-has-a-few-mistakes-and-inaccuracies-in-it.aspx</id><published>2008-10-18T05:34:00Z</published><updated>2008-10-18T05:34:00Z</updated><content type="html">&lt;P&gt;A few things occurred to me the other day while I was playing around with my COM connection point code and I realized that my article contains a number of errors. I intend to correct these some time and then I'll republish it as soon as possible. Please call back later!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9004159" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author></entry><entry><title>COM eventing</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/10/11/com-eventing.aspx" /><id>http://blogs.msdn.com/rcook/archive/2008/10/11/com-eventing.aspx</id><published>2008-10-12T01:37:00Z</published><updated>2008-10-12T01:37:00Z</updated><content type="html">My first article (&lt;A class="" href="http://blogs.msdn.com/rcook/pages/iconnectionpoint-and-net-or-how-i-learned-to-stop-worrying-and-love-managed-event-sinks-part-1.aspx" mce_href="http://blogs.msdn.com/rcook/pages/iconnectionpoint-and-net-or-how-i-learned-to-stop-worrying-and-love-managed-event-sinks-part-1.aspx"&gt;IConnectionPoint and .NET&lt;/A&gt;) is a multi-part discussion contrasting .NET delegate-style event handling with classic COM IConnectionPoint eventing from managed code. Excel is my choice of &lt;STRIKE&gt;victim&lt;/STRIKE&gt; application.&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8996410" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author><category term="PIAs" scheme="http://blogs.msdn.com/rcook/archive/tags/PIAs/default.aspx" /><category term="Excel" scheme="http://blogs.msdn.com/rcook/archive/tags/Excel/default.aspx" /><category term="Office" scheme="http://blogs.msdn.com/rcook/archive/tags/Office/default.aspx" /><category term="COM" scheme="http://blogs.msdn.com/rcook/archive/tags/COM/default.aspx" /><category term=".NET" scheme="http://blogs.msdn.com/rcook/archive/tags/.NET/default.aspx" /><category term="VSTO" scheme="http://blogs.msdn.com/rcook/archive/tags/VSTO/default.aspx" /></entry><entry><title>Welcome</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rcook/archive/2008/10/11/welcome.aspx" /><id>http://blogs.msdn.com/rcook/archive/2008/10/11/welcome.aspx</id><published>2008-10-12T01:35:00Z</published><updated>2008-10-12T01:35:00Z</updated><content type="html">My name's Richard and I'm a developer in the &lt;A class="" href="http://msdn.microsoft.com/en-us/office/aa905533.aspx" mce_href="http://msdn.microsoft.com/en-us/office/aa905533.aspx"&gt;Visual Studio Tools for Office&lt;/A&gt; team at Microsoft.&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8996408" width="1" height="1"&gt;</content><author><name>rcook</name><uri>http://blogs.msdn.com/members/rcook.aspx</uri></author></entry></feed>