LayoutKind 열거형
비관리 코드로 내보낼 때 개체의 레이아웃을 제어합니다.
네임스페이스: System.Runtime.InteropServices
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration LayoutKind
‘사용 방법
Dim instance As LayoutKind
[SerializableAttribute]
[ComVisibleAttribute(true)]
public enum LayoutKind
[SerializableAttribute]
[ComVisibleAttribute(true)]
public enum class LayoutKind
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
public enum LayoutKind
SerializableAttribute
ComVisibleAttribute(true)
public enum LayoutKind
멤버
멤버 이름 | 설명 | |
---|---|---|
![]() |
Auto | 런타임에서는 자동으로 관리되지 않는 메모리에 있는 개체의 멤버에 적합한 레이아웃을 선택합니다. 이 열거형 멤버로 정의된 개체는 관리 코드 외부에 노출시킬 수 없습니다. 관리 코드 외부에 노출시키려고 하면 예외가 발생합니다. |
![]() |
Explicit | 관리되지 않는 메모리에 있는 개체의 각 멤버에 대한 정확한 위치는 명시적으로 제어됩니다. 각 멤버는 FieldOffsetAttribute를 사용하여 형식 내부에서 필드의 위치를 나타내야 합니다. |
![]() |
Sequential | 개체의 멤버는 관리되지 않는 메모리로 내보낼 때 표시되는 순서대로 배치됩니다. 멤버는 StructLayoutAttribute.Pack에서 지정된 방식에 따라 배치되며, 연속되지 않을 수 있습니다. |
설명
이 열거형은 StructLayoutAttribute와 함께 사용됩니다. 공용 언어 런타임에서는 기본적으로 Auto 레이아웃을 사용합니다. Auto 값과 관련된 레이아웃 문제를 줄이기 위해 C#, Visual Basic 및 C++ 컴파일러는 값 형식에 대해 Sequential 레이아웃을 지정합니다.
예제
다음 예제에서는 PtInRect 함수의 관리되는 선언을 보여 줍니다. 이 함수는 사각형 내에 점이 있는지 여부를 검사하고, Sequential 레이아웃을 사용하여 Point 구조체를 정의하고, Explicit 레이아웃을 사용하여 Rect 구조체를 정의합니다.
Enum Bool
[False] = 0
[True]
End Enum 'Bool
<StructLayout(LayoutKind.Sequential)> _
Public Structure Point
Public x As Integer
Public y As Integer
End Structure 'Point
<StructLayout(LayoutKind.Explicit)> _
Public Structure Rect
<FieldOffset(0)> Public left As Integer
<FieldOffset(4)> Public top As Integer
<FieldOffset(8)> Public right As Integer
<FieldOffset(12)> Public bottom As Integer
End Structure 'Rect
Class LibWrapper
<DllImport("user32.dll", CallingConvention := CallingConvention.StdCall)> _
Public Shared Function PtInRect(ByRef r As Rect, p As Point) As Bool
End Function
End Class 'LibWrapper
Class TestApplication
Public Shared Sub Main()
Try
Dim bPointInRect As Bool = 0
Dim myRect As New Rect()
myRect.left = 10
myRect.right = 100
myRect.top = 10
myRect.bottom = 100
Dim myPoint As New Point()
myPoint.x = 50
myPoint.y = 50
bPointInRect = LibWrapper.PtInRect(myRect, myPoint)
If bPointInRect = Bool.True Then
Console.WriteLine("Point lies within the Rect")
Else
Console.WriteLine("Point did not lies within the Rect")
End If
Catch e As Exception
Console.WriteLine(("Exception : " + e.Message.ToString()))
End Try
End Sub 'Main
End Class 'TestApplication
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;
}
class LibWrapper
{
[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall)]
public 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 = LibWrapper.PtInRect(ref myRect, myPoint);
if(bPointInRect == Bool.True)
Console.WriteLine("Point lies within the Rect");
else
Console.WriteLine("Point did not lies within the Rect");
}
catch(Exception e)
{
Console.WriteLine("Exception : " + e.Message);
}
}
}
enum class Bool
{
False = 0,
True
};
[StructLayout(LayoutKind::Sequential)]
value struct Point
{
public:
int x;
int y;
};
[StructLayout(LayoutKind::Explicit)]
value struct Rect
{
public:
[FieldOffset(0)]
int left;
[FieldOffset(4)]
int top;
[FieldOffset(8)]
int right;
[FieldOffset(12)]
int bottom;
};
ref class LibWrapper
{
public:
[DllImport("user32.dll",CallingConvention=CallingConvention::StdCall)]
static Bool PtInRect( Rect * r, Point p );
};
int main()
{
try
{
Bool bPointInRect = (Bool)0;
Rect myRect = Rect( );
myRect.left = 10;
myRect.right = 100;
myRect.top = 10;
myRect.bottom = 100;
Point myPoint = Point( );
myPoint.x = 50;
myPoint.y = 50;
bPointInRect = LibWrapper::PtInRect( &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 : {0}", e->Message );
}
}
enum Bool
{
False (0),
True (1);
} //Bool
/** @attribute StructLayout(LayoutKind.Sequential)
*/
public class Point
{
public static int x;
public static int y;
} //Point
/** @attribute StructLayout(LayoutKind.Explicit)
*/
public class Rect
{
/** @attribute FieldOffset(0) */ public int left;
/** @attribute FieldOffset(4) */ public int top;
/** @attribute FieldOffset(8) */ public int right;
/** @attribute FieldOffset(12) */ public int bottom;
} //Rect
class LibWrapper
{
/** @attribute DllImport("user32.dll",
CallingConvention = CallingConvention.StdCall)
*/
public static native Bool PtInRect(/** @ref */ Rect r, Point p);
} //LibWrapper
class TestApplication
{
public static void main(String[] args)
{
try {
Bool bPointInRect = (Bool)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 = LibWrapper.PtInRect(/** @ ref */ myRect, myPoint);
if (bPointInRect.Equals(Bool.True)) {
Console.WriteLine("Point lies within the Rect");
}
else {
Console.WriteLine("Point does not lie within the Rect");
}
}
catch (System.Exception e) {
Console.WriteLine("Exception : " + e.get_Message());
}
} //main
} //TestApplication
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원