マーシャリングに問題があります。
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class Book
{
[MarshalAs(UnmanagedType.LPArray, SizeConst = 1000)]
public Page[] astInject2;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class Page
{
public int n;
}
Marshal.SizeOf(typeof(Book))を呼び出すとArgumentException がスローされる理由:
Type 'Book' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed.
?
解決策はありますか?
Book オブジェクトを C++ 構造体にマーシャリングしています。
私がこれを行う場合:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Book
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1000)]
public Page[] astInject2;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Page
{
public int n;
}
その後、Marshal.SizeOf(typeof(Book))
4000 が返されます。Book を構造体として定義できないことに注意してください。クラスでなければなりません。