locked
C# equivalent for C++ GetLastError()-method? RRS feed

  • Question

  • Is there a C# equivalent for the C++ GetLastError()-method? (defined in winbase.h)
    Thursday, April 13, 2006 8:03 AM

Answers

  • If you use PInvoke calls, set SetLastError=true in the DllImport attribute and then call Marshal.GetLastWin32Error after. Don't try to call GetLastError directly.

     

    Thursday, April 13, 2006 1:18 PM

All replies

  • The normal .NET way of reporting errors is to use exceptions rather than returning status codes. If you're using interop, you can make an external call to GetLastError (I don't have the details to hand, but there are bound to be plenty of pages on it).

    Does that help?

    Jon

    Thursday, April 13, 2006 10:19 AM
  • If you use PInvoke calls, set SetLastError=true in the DllImport attribute and then call Marshal.GetLastWin32Error after. Don't try to call GetLastError directly.

     

    Thursday, April 13, 2006 1:18 PM
  • Funny that you reply to a thread that's five years old :)
    Mattias, C# MVP
    Friday, March 11, 2011 4:13 PM