Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
getlasterror (coredll)
 

coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for getlasterror in other DLLs exists, click on Find References to the right.

.
Summary
GetLastError- retrieves the last system error.

C# Signature:

[DllImport("coredll.dll", SetLastError=true)]
static extern Int32 GetLastError();

VB Signature:

Declare Function GetLastError Lib "coredll.dll" () As Int32

User-Defined Types:

None.

Notes:

It is recommended that you do not call the Win32 GetLastError method directly. Because of the way P/Invoke works, the error message may get reset between Win32 calls in your code. Instead, call the Marshal.GetLastWin32Error method, which can be combined with the ever useful Marshal.ThrowExceptionForHR method. See below for an example.

Tips & Tricks:

You can look up Windows Mobile specific error codes here: http://msdn.microsoft.com/en-us/library/aa914935.aspx

Sample Code:

C#

// don't use this!
Int32 lastError = GetLastError();

// use this:
int lastError = Marshal.GetLastWin32Error();

// or this:
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());

VB

// don't use!
Dim lastError As Int32
lastError = GetLastError()

// use this:
Dim lastError As int
lastError = Marshal.GetLastWin32Error()

// or
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error())

Alternative Managed API:

Marshal.GetLastWin32Error();

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions