您的位置:首页 > 大数据 > 人工智能

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐