P/Invoke is like a poke in the eye. Sure the P/Invoke wiki made life a lot more palatable, but it’s at best incomplete, at worst inaccurate, and invariably you’ll find yourself hand-crafting signatures based on Win32 API doco and bringing a production server to its knees because of a stack imbalance.

In my idler moments I’ve often thought that surely parsing the source-of-truth Win32 header files and spitting out P/Invoke signatures couldn’t be that hard. Fortunately for everyone, the Microsoft Interop Team thought so too[1], and released the P/Invoke Interop Assistant to Codeplex. Really that was about 2 years ago, but I only just noticed, so it’s still exciting for me.

As I know it this has been made simpler because Microsoft have been standardizing their header files and adding some additional metadata [2], which makes it possible to generate accurate signatures (and, presumably, to generate MSDN doco).

Sadly of course, none of this does anything to make any of the underlying API’s any simpler to use…

 

[1] Really if you look on Wikipedia, turn’s out there’s a honest few around.
[2] In retrospect you wonder why managed code took so long to take off as a concept, given how enormously fragile the previous model really was. SAL’s a fantastic thought, but only highlights how fundamental the problem is.


Check it out:Cup(Of T)