The last Win32 error can be reset as a result of making managed calls, due to P/Invokes called by the runtime itself. In ...

The last Win32 error can be reset as a result of making managed calls, due to P/Invokes called by the runtime itself. In order to ensure the correctness of the value returned by GetLastWin32Error, place the call immediately after the relevant platform invoke call in your code.