C++
HRESULT New1(int ar[10]);
HRESULT New2(double ar[10][20]);
HRESULT New3(LPWStr ar[10]);
C#
void New1([MarshalAs(UnmanagedType.LPArray, SizeConst=10)] int[] ar);
void New2([MarshalAs(UnmanagedType.LPArray, SizeConst=200)] double[] ar);
void New2([MarshalAs(UnmanagedType.LPArray,
ArraySubType=UnmanagedType.LPWStr, SizeConst=10)] String[] ar);
C++
HRESULT New1(int ar[]);
HRESULT New2(int ArSize, [size_is(ArSize)] double ar[]);
HRESULT New3(int ElemCnt, [length_is(ElemCnt)] LPStr ar[]);
C#
void New1(ref int ar);
void New2(ref double ar);
void New3(ref String ar);
배열의 요소 수를 지정하는 방법
1. 배열의 요소 수가 포함된 또 다른 매개 변수 식별, 매개 변수는 위치로 식별
void New(
int ElemCnt,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)] int[] ar);
2. 배열의 크기를 상수로 정의
void New(
[MarshalAs(UnmanagedType.LPArray, SizeConst=128)] int[] ar);
구조체 내의 배열
C++
struct MyStruct {
int values[128];
};
C#
[StructLayout(LayoutKind.Sequential)]
public struct MyStruct
{
[MarshalAs(UnmanagedType.ByValArray, SizeConstant = 128)] public int[] values;
}
struct Image {
unsigned char* image_ptr;
int rows;
int cols;
};
typedef void (*pfnCallback)(bool[], const char* [], Image[], Image, int length);
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Image
{
public IntPtr image_ptr;
public int rows;
public int cols;
}
public delegate void dgCallback(
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1, SizeParamIndex = 4)] bool[] status,
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 4)] string[] id,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] Image[] img_face,
Image img_org,
int length);
'.NET > C#' 카테고리의 다른 글
Concurrency (동시성) (0) | 2023.08.16 |
---|---|
Marshaling: 복사 및 고정 (0) | 2021.10.15 |
Comparisons and Sorts (0) | 2021.10.15 |
Debugging Tips (0) | 2021.09.15 |
Equals, IEquatable<T> (0) | 2021.08.15 |