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
Download Visual Studio Add-In

WINERROR (Constants)
 
.

Important Note about .NET and Win32 error-code reading:

It is documented that you should NOT use the pinvoke GetLastError() due to the fact that the runtime

makes it's own API calls without any notification to the application at all. And since most user-API calls

are made through a call setup with DllImportAttribute, the .NET framework has made available a method

that will record your call's ErrorCode until such time as you need to get it (although, most times, subsequent calls

to other API's that you make will overwrite the previous - read ahead to find out why). Use Marshal.GetLastWin32Error() to get the

last ErrorCode recorded by your most recent API call. You will also need to make sure you change SetLastError=true when you define

your Pinvoke signature, unless you purposely don't want it or don't care or need the lasterror preserved. If you have

questions on this remit to: http://www.paradisim.net in the FAQ forums or gabriel@paradisim.net.

With this said, you can still use the following code to identify the errorcode:

/******************************************************************************/
/*       _                                    */
/*       \`*-.                                */
/*    )  _`-.                                 */
/*       .  : `. .                                */
/*       : _   '  \                               */
/*       ; *` _.   `*-._                              */
/*       `-.-'      `-.                           */
/*     ;       `       `.                         */
/*     :.       .    \                        */
/*     . \  .   :   .-'   .     NABU Project                  */
/*     '  `+.;  ;  '      :     Microsoft.Win32.Interop Library       */
/*     :  '  |    ;       ;-.   Copyright © 2005, adontz          */
/*     ; '   : :`-:     _.`* ;                        */
/*      .*' /  .*' ; .*`- +'  `*'                         */
/*      `*-*   `*-*  `*-*'                            */
/*                                        */
/******************************************************************************/
using System;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Reflection;

namespace Microsoft.Win32.Interop
{
    public class ResultWin32
    {
        public static string GetErrorName(int ErrCode)
        {
            Win32Exception i_Ex = new Win32Exception(ErrCode);
            return i_Ex.Message;
        }
    }
}
/******************************************************************************/
/*                END OF FILE                 */
/******************************************************************************/

 

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it!

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