本文整理汇总了C#中System.Runtime.InteropServices.LayoutKind枚举的典型用法代码示例。如果您正苦于以下问题:C# LayoutKind枚举的具体用法?C# LayoutKind怎么用?C# LayoutKind使用的例子?那么恭喜您, 这里精选的枚举代码示例或许可以为您提供帮助。
在下文中一共展示了LayoutKind枚举的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
enum Bool
{
False = 0,
True
};
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Explicit)]
public struct Rect
{
[FieldOffset(0)] public int left;
[FieldOffset(4)] public int top;
[FieldOffset(8)] public int right;
[FieldOffset(12)] public int bottom;
}
internal static class NativeMethods
{
[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall)]
internal static extern Bool PtInRect(ref Rect r, Point p);
};
class TestApplication
{
public static void Main()
{
try
{
Bool bPointInRect = 0;
Rect myRect = new Rect();
myRect.left = 10;
myRect.right = 100;
myRect.top = 10;
myRect.bottom = 100;
Point myPoint = new Point();
myPoint.x = 50;
myPoint.y = 50;
bPointInRect = NativeMethods.PtInRect(ref myRect, myPoint);
if(bPointInRect == Bool.True)
Console.WriteLine("Point lies within the Rect");
else
Console.WriteLine("Point did not lie within the Rect");
}
catch(Exception e)
{
Console.WriteLine("Exception : " + e.Message);
}
}
}