Platform Invoke
Although the focus of this book is COM Interop, I would be remiss if I didn't discuss Platform Invocation Service (PInvoke), which allows you to call non-COM DLLs, Windows API and System functions. To use PInvoke perform the following steps:
- Declare a function in your managed code that has an equivalent parameter list and return value to the unmanaged function. You will need to use the static and extern keyword in your function declaration.
- Use the System.Runtime.InteropServices.DllImport attribute on your function declaration to (among other things) indicate which unmanaged DLL the implementation of the method resides in.
- Optionally specify custom marshaling attributes for the parameters and return values if necessary.
- Call the ...
Get .NET and COM Interoperability Handbook, The now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.