C# using PInvoke to call an unmanaged DLL
Recently I've found myself having to do some pinvoking with .net. Microsoft offers an excellent primer on the subject. http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx For it's many great benefits the .net framework doesn't do everything. You will find yourself having to invoke a win32 API function call at some point in your career. I'm going to offer some quick and dirty samples on getting data back and forth using the platform invoke. First you cannot invoke any classes using pinvoke. You get 1 function call at a time. If you want classes you will need to write a custom CLI/C++ wrapper. But that goes beyond the scope of this post. First let's look at the unmanaged\win32 side of things. Let's say you have a dll called MyDll.dll. In this dll you have a bunch of functions. // this lets use export functions from the dll #define DllExport __declspec( dllexport ) // first we use extern "C" so we don't get name mang...