私は次のC++構造体を持っています
typedef struct {
char szAccountNo[11];
char szAccountName[40];
char act_pdt_cdz3[3];
char amn_tab_cdz4[4];
char expr_datez8[8];
char granted;
char filler[189];
}ACCOUNTINFO;
typedef struct {
char szDate [14];
char szServerName [15];
char szUserID [8];
char szAccountCount [3];
ACCOUNTINFO accountlist [999];
}LOGININFO;
typedef struct{
int TrIndex;
LOGININFO *pLoginInfo;
}LOGINBLOCK;
そしてC#クラスに変換
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class ACCOUNTINFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
public string szAccountNo;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
public string szAccountName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
public string act_pdt_cdz3;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
public string amn_tab_cdz4;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
public string expr_datez8;
public char granted;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 189)]
public string filler;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class LOGININFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
public string szDate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 15)]
public string szServerName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
public string szUserID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
public string szAccountCount;
[MarshalAs(UnmanagedType.Struct, SizeConst = 99)]
public ACCOUNTINFO[] accountlist;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class LOGINBLOCK
{
[MarshalAs(UnmanagedType.I4)]
public int TrIndex;
[MarshalAs(UnmanagedType.Struct, SizeConst = 1)]
public LOGININFO pLoginInfo;
};
次の 2 つの方法を使用して、WndProc 内の LParam を変換しました。
1. TrStruct.LOGINBLOCK lb = new TrStruct.LOGINBLOCK();
lb = (TrStruct.LOGINBLOCK)m.GetLParam(typeof(TrStruct.LOGINBLOCK));
2. TrStruct.LOGINBLOCK lb = (TrStruct.LOGINBLOCK) Marshal.PtrToStructure(m.LParam, typeof(TrStruct.LOGINBLOCK));
ただし、成功せず、通常のエラー メッセージも出力されません。代わりに、出力ウィンドウに「mscorlib.dll で 'System.TypeLoadException' 型の初めての例外が発生しました」というメッセージが表示されます。変換の何が問題なのか誰か教えてもらえますか?