I recently delivered a half-day instructor-led training on .NET Interoperability, including P/Invoke, COM Interop and C++/CLI. I’m sharing the exercises and solutions with you in the hope you might find them useful. All the exercises are taken from (almost) real-life scenarios I had to implement at some point in the past.
Among the exercises:
- Wrap System.IO.FileSystemWatcher for use from native C++ code
- Provide a managed class that acts as a byte array allocated from a Win32 low-fragmentation heap (LFH)
- Expose System.Text.RegularExpressions.Regex to clients through COM interop and consume it from VBScript
The exercises and solutions can be downloaded from my SkyDrive.
With the advent of Windows Vista, Windows Server 2008 and the soon-expected Windows 7, the need for interoperability solutions is becoming clearer than ever before – most of the system APIs have no managed counterparts and wrapping them properly becomes a means to implementing any kind of solution on top of Windows. Hopefully, community efforts and Microsoft investments will provide an exhaustive managed layer of some form for current and future versions of Windows.