Posts about Native Interop
This week the annual Microsoft conference NT konferenca 2011 was taking place in Portorož. On Tuesday I had a talk there about the Windows API Code Pack. As promised, you can find the slides from this talk in my OneDrive.
.NET Framework 2.0 Service Pack 1 caused the C# compiler in Visual Studio 2005 and later to set the NXCOMPAT bit for all build targets without an option to turn this new behavior off. This means that DEP (data execution prevention) will kick in unless it is turned off completely in the operating system.
By switching from C# with P/Invoke calls to Managed C++ when implementing a managed wrapper for the ANSI C style library I stumbled upon, I wanted to avoid the tedious and error-prone task of writing the P/Invoke signatures for function calls and user-defined types for the structures they used. As a side result I also managed to avoid most of the advanced marshaling issues with complex data structures.
Managed C++ is actually quite nice in the 2005 version. You probably still wouldn't want to use it if you could get away with C# or VB. But if platform invoke is giving you too many headaches, you might want to take a look at it.
For anybody else like me out there who hasn't done more than an occasional DllImport call or two, the following resources should help getting to grips with the PInvoke basics.