Open Source .Net Development
Web Services Security
Luckily the WinIO Parallel Port API (http://www.internals.com/) didn’t really use pointers or structures and was easily wrapped in C#. I also like the consistent interface that worked on everything from Win98 to WinXP! Probably the handiest trick I came across in using P/Invoke was in retrieving Win32 errors. Instead of trying to import GetLastError and FormatMessage (which requires the use of pointers and the unsafe compiler directive), there is a much simpler way. Check out this one line treasure:
Win32Exception w32e = new Win32Exception(Marshal.GetLastWin32Error());
Then you can just throw another exception:
throw(new ApplicationException(w32e.Message));
and let the someone else handle it!