Is there any way to get detailed error information for Win32 errors when using Platform Invoke?
2004-08-30 11:35
721 查看
you can use the FormatMessage Win32 API. Sample projects for C# and VB.NET are enclosed. This is how the declaration looks like:
[DllImport("Kernel32.dll")] |
public static extern int FormatMessage(int flags, IntPtr source, int messageId, int languageId, StringBuilder |
buffer, int size, IntPtr arguments ); |
Called like so: |
// You can call FormatMessage to get a descriptive error message |
StringBuilder sbFormatMessage = new StringBuilder(1024); |
retVal = Interop.FormatMessage(Interop.FORMAT_MESSAGE_FROM_SYSTEM, IntPtr.Zero, Marshal.GetLastWin32Error(), 0, sbFormatMessage, |
sbFormatMessage.Capacity, IntPtr.Zero); |
Download C# sample, formatmessage.zip Download VB.NET sample, formatmessage_VB.zip |
相关文章推荐
- Using SAPI is there a way to enter pinyin for Chinese pronunciation
- Is there any way to define a min and max value for edittext in android?
- How to solve install error ".NET Framework 2.0 is not detected." when installing VS tools SDK for GP 10.0
- Is there a way to get a Cursor from a GreenDao Query object?
- mysqldump: Got error: 1044: Access denied for user 'sunyard'@'%' to database 'fac_demo' when using L
- There is no tracking information for the current branch.If you wish to set tracking information for
- Unable to start debugging on the web server. The web server is not configured correctly. See help for common configuration errors. Running the web page outside of the debugger may provide further information.
- mysqldump执行时Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
- Is there a way to loop through a table variable in TSQL without using a cursor?
- Q:Is there any way to define what the "Open Resource" dialog in Eclipse should show?
- Using Diagwait as a diagnostic to get more information for diagnosing Oracle Clusterware Node evicti
- mysqldump: Got error: 1142: SELECT, LOCK TABLES command denied to user 'root'@'localhost' for table 'accounts' when using LOCK TABLES
- Downloading files from a server to client, using ASP.Net, when file size is too big for MemoryStream using Generic Handlers (ashx)
- unable to get system library for the project" error when import android project to eclips
- Is there any way to kill a Thread in Python?
- Are you looking for a way to get the entire text of a word document into a RichEdit without using the Clipboard?
- 【phonegap】移动WEB开发--常见问题 Error "There is no script engine for file extension" when running .js files
- Is there any best way to reduce the size of ibdata in mysql.?
- 关于Error:Minifying the variant used for tests is not supported when using Jack.
- There's no Qt version assigned to this project for platform Win32