マーシャリングできません: 無効なマネージ/アンマネージ型の組み合わせです。
以下の試しのコードを実行したところ、マーシャリングのエラーになった。
namespace Examples { public partial class ExampleForm : Form { private void listBoxFont_SelectedIndexChanged(object sender, EventArgs e) { fontFace = new Face(lib, Path.Combine(Path.GetFullPath(fontFolder), (string)listBoxFont.SelectedItem)); fontFace.SetCharSize(0, 62, 0, 96); SharpFont.TrueType.OS2 os2Table = (SharpFont.TrueType.OS2)fontFace.GetSfntTable(SharpFont.TrueType.SfntTag.OS2); /* 試しのコード */ pictureBoxText.Invalidate(); }
スレッド 0x2e78 はコード 0 (0x0) で終了しました。 'Examples.vshost.exe' (CLR v2.0.50727: Examples.vshost.exe): 'D:\08_MyGitHub\SharpFont\Binaries\Examples\Debug\Examples.exe' が読み込まれました。シンボルが読み込まれました。 'Examples.vshost.exe' (CLR v2.0.50727: Examples.vshost.exe): 'C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms.resources\2.0.0.0_ja_b77a5c561934e089\System.Windows.Forms.resources.dll' が読み込まれました。モジュールがシンボルなしでビルドされました。 'Examples.vshost.exe' (CLR v2.0.50727: Examples.vshost.exe): 'D:\08_MyGitHub\SharpFont\Binaries\Examples\Debug\SharpFont.dll' が読み込まれました。シンボルが読み込まれました。 'Examples.vshost.exe' (CLR v2.0.50727: Examples.vshost.exe): 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' が読み込まれました。 シンボルの読み込みをスキップしました。 モジュールは最適化されていて、デバッグ オプションの [マイ コードのみ] 設定が有効になっています。 例外がスローされました: 'System.TypeLoadException' (mscorlib.dll の中) 型 'System.TypeLoadException' のハンドルされていない例外が mscorlib.dll で発生しました 追加情報:型 'SharpFont.TrueType.Internal.OS2Rec' のフィールド 'panose' をマーシャリングできません: 無効なマネージ/アンマネージ型の組み合わせです。 配列フィールドは ByValArray または SafeArray と組で使用してください。 プログラム '[0x1CA4] Examples.vshost.exe' はコード -1073740771 (0xc000041d) で終了しました。
OS2クラスは、以下のような内容。
namespace SharpFont.TrueType { public class OS2 { private IntPtr reference; private OS2Rec rec; internal OS2(IntPtr reference) { Reference = reference; } internal IntPtr Reference { get { return reference; } set { reference = value; rec = PInvokeHelper.PtrToStructure<OS2Rec>(reference); /* 構造体へ変換(マーシャリング)*/ } } } }
namespace SharpFont { public sealed class Face : IDisposable { public object GetSfntTable(SfntTag tag) { IntPtr tableRef = FT.FT_Get_Sfnt_Table(Reference, tag); if (tableRef == IntPtr.Zero) return null; switch (tag) { case SfntTag.Header: return new Header(tableRef); case SfntTag.HorizontalHeader: return new HoriHeader(tableRef); case SfntTag.MaxProfile: return new MaxProfile(tableRef); case SfntTag.OS2: return new OS2(tableRef); case SfntTag.Pclt: return new Pclt(tableRef); case SfntTag.Postscript: return new Postscript(tableRef); case SfntTag.VertHeader: return new VertHeader(tableRef); default: return null; } } } } ||< ></blockquote>< ><blockquote cite="https://github.com/Robmaister/SharpFont/blob/e20f1a46a0832cea7e207eacd8fb46a46a4cdb64/Source/SharpFont/TrueType/SfntTag.cs#L33" title="SharpFont/SfntTag.cs at e20f1a46a0832cea7e207eacd8fb46a46a4cdb64 揃 Robmaister/SharpFont">< >|cs| namespace SharpFont.TrueType { public enum SfntTag { Header = 0, MaxProfile = 1, OS2 = 2, HorizontalHeader = 3, VertHeader = 4, Postscript = 5, Pclt = 6 } }