本文整理汇总了C#中System.Runtime.InteropServices.Marshal.GetLastWin32Error方法的典型用法代码示例。如果您正苦于以下问题:C# Marshal.GetLastWin32Error方法的具体用法?C# Marshal.GetLastWin32Error怎么用?C# Marshal.GetLastWin32Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.InteropServices.Marshal
的用法示例。
在下文中一共展示了Marshal.GetLastWin32Error方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MessageBox
//引入命名空间
using System;
using System.Runtime.InteropServices;
internal class Win32
{
// Use DllImportAttribute to inport the Win32 MessageBox
// function. Set the SetLastError flag to true to allow
// the function to set the Win32 error.
[DllImportAttribute("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hwnd, String text, String caption, uint type);
}
class Program
{
static void Run()
{
// Call the MessageBox with normal parameters.
Console.WriteLine("Calling Win32 MessageBox without error...");
Win32.MessageBox(new IntPtr(0), "Press OK...", "Press OK Dialog", 0);
// Get the last error and display it.
int error = Marshal.GetLastWin32Error();
Console.WriteLine("The last Win32 Error was: " + error);
// Call the MessageBox with an invalid window handle to
// produce a Win32 error.
Console.WriteLine("Calling Win32 MessageBox with error...");
Win32.MessageBox(new IntPtr(123132), "Press OK...", "Press OK Dialog", 0);
// Get the last error and display it.
error = Marshal.GetLastWin32Error();
Console.WriteLine("The last Win32 Error was: " + error);
}
static void Main(string[] args)
{
Run();
}
}
// This code example displays the following to the console:
//
// Calling Win32 MessageBox without error...
// The last Win32 Error was: 0
// Calling Win32 MessageBox with error...
// The last Win32 Error was: 1400