C# Get Win32 Error Code
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About win32 error code returned by the print processor 259 Us Learn more about Stack Overflow the company Business Learn more about hiring win32 error code 1797 developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the
Win32 Error Code Returned By The Print Processor 122
Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Getting the Windows System Error Code
Win32 Error Code Returned By The Print Processor 0x3f
title/description from it's hex number up vote 18 down vote favorite 6 I'm messing around with some windows functions using p/invoke. Occasionally, I get an error code that is not ERROR_SUCCESS (such an odd name). Is there a way to look these up within the program? Forexample, if I get error 1017. Can I tell the user The system has attempted to load or restore a win32 error code 10061 file into the registry, but the specified file is not in a registry file format. (ERROR_NOT_REGISTRY_FILE: 0x3F9) Instead of Error Code: 1017 c# .net windows pinvoke share|improve this question asked Oct 30 '09 at 16:19 Malfist 13.5k43141248 add a comment| 4 Answers 4 active oldest votes up vote 58 down vote accepted I'm not sure if there's a niifty .NET wrapper, but you could call the FormatMessage API using P/Invoke. See this answer for how it would normally be called from native code. Though the question refers to grabbing error codes from HRESULTs, the answer also applies for retreiving codes from the regular OS error codes coming from GetLastError/GetLastWin32Error). EDIT: Thanks Malfist for pointing me to pinvoke.net, which includes alternative, managed API: using System.ComponentModel; string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message; Console.WriteLine(errorMessage); share|improve this answer edited Dec 16 '15 at 5:08 Mark Lakata 9,88035369 answered Oct 30 '09 at 16:23 Nick Meyer 19.7k94665 2 pinvoke.net/default.aspx/kernel32/FormatMessage.html Says never to use FormatMessage –Malfist Oct 30 '09 at 16:33 @Malfist, thanks for pointing that out. There is a reply there that says it's okay as long as you're using Marshal.GetLastWin32Error to retrieve the error code. Nonetheless, it looks
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students
Win32 Error Code Returned By The Print Processor 2250
Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events win32 error code 87 Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired win32 error code returned by the print processor 0x0 content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. System.Runtime.InteropServices Marshal Class http://stackoverflow.com/questions/1650838/getting-the-windows-system-error-code-title-description-from-its-hex-number Marshal Methods Marshal Methods GetLastWin32Error Method GetLastWin32Error Method GetLastWin32Error Method AddRef Method AllocCoTaskMem Method AllocHGlobal Method AreComObjectsAvailableForCleanup Method BindToMoniker Method ChangeWrapperHandleStrength Method CleanupUnusedObjectsInCurrentContext Method Copy Method CreateAggregatedObject Method CreateWrapperOfType Method DestroyStructure Method FinalReleaseComObject Method FreeBSTR Method FreeCoTaskMem Method FreeHGlobal Method GenerateGuidForType Method GenerateProgIdForType Method https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getlastwin32error(v=vs.110).aspx GetActiveObject Method GetComInterfaceForObject Method GetComInterfaceForObjectInContext Method GetComObjectData Method GetComSlotForMethodInfo Method GetDelegateForFunctionPointer Method GetEndComSlot Method GetExceptionCode Method GetExceptionForHR Method GetExceptionPointers Method GetFunctionPointerForDelegate Method GetHINSTANCE Method GetHRForException Method GetHRForLastWin32Error Method GetIDispatchForObject Method GetIDispatchForObjectInContext Method GetITypeInfoForType Method GetIUnknownForObject Method GetIUnknownForObjectInContext Method GetLastWin32Error Method GetManagedThunkForUnmanagedMethodPtr Method GetMethodInfoForComSlot Method GetNativeVariantForObject Method GetObjectForIUnknown Method GetObjectForNativeVariant Method GetObjectsForNativeVariants Method GetStartComSlot Method GetThreadFromFiberCookie Method GetTypedObjectForIUnknown Method GetTypeForITypeInfo Method GetTypeFromCLSID Method GetTypeInfoName Method GetTypeLibGuid Method GetTypeLibGuidForAssembly Method GetTypeLibLcid Method GetTypeLibName Method GetTypeLibVersionForAssembly Method GetUniqueObjectForIUnknown Method GetUnmanagedThunkForManagedMethodPtr Method IsComObject Method IsTypeVisibleFromCom Method NumParamBytes Method OffsetOf Method Prelink Method PrelinkAll Method PtrToStringAnsi Method PtrToStringAuto Method PtrToStringBSTR Method PtrToStringUni Method PtrToStructure Method QueryInterface Method ReadByte Method ReadInt16 Method ReadInt32 Method ReadInt64 Method ReadIntPtr Method ReAllocCoTaskMem Method ReAllocHGlobal Method Release Method ReleaseComObject Method ReleaseThreadCache Method SecureStringToBSTR Method SecureStringToCoTaskMemAnsi Method SecureStringToCoTaskMemUnicode Me
SQL Server 2014 Express resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums https://social.msdn.microsoft.com/Forums/en-US/9df01d21-8eb3-4733-9bc7-009ab52fda2d/c-equivalent-for-c-getlasterrormethod?forum=csharplanguage Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: C# equivalent for C++ GetLastError()-method? Archived Forums win32 error V > Visual C# Language Question 0 Sign in to vote Is there a C# equivalent for the C++ GetLastError()-method? (defined in winbase.h) Thursday, April 13, 2006 8:03 AM Answers 3 Sign in to vote If you use PInvoke calls, set SetLastError=true in the DllImport attribute and then call Marshal.GetLastWin32Error after. Don't try to call GetLastError win32 error code directly. Thursday, April 13, 2006 1:18 PM All replies 0 Sign in to vote 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 3 Sign in to vote 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 0 Sign in to vote See http://blogs.msdn.com/b/adam_nathan/archive/2003/04/25/56643.aspx Friday, March 11, 2011 10:28 AM 0 Sign in to vote Funny that you reply to a thread that's five years old :)Mattias, C# MVP Friday, March 11, 2011 4:13 PM Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the online survey will