[問題] Marshal相關問題
大家好
最近在練習Marshal的部分
目前知道Marshal是用在Managed與Unmanaged傳送資料時的型別轉換
也找了些範例來練習:
(http://vito-note.blogspot.tw/2012/05/unmanaged.html)
現在我有個題目 是要marshal C++ structure
例如:
typedef struct {
DWORD DWord1;
LPTSTR Lptstr;
} VarTestBufData_DEF;
我有幾個疑問
1.marshal是用在傳送資料時做型別轉換用途的,那這題目要我直接marshal 不懂題目意
思
2.上面網址中有個轉換表 像是DWORD → UInt32, LPTSTR → String或StringBuilder
這題目是要做類似這樣的事嗎? 那struct要使用StructLayoutAttribute?
以下是我參考範例試著做:
[StructLayout(LayoutKind.Sequential)]
public struct VarTestBufData_DEF
{
[MarshalAs(UnmanagedType.UInt32)]
public DWORD DWord1;
[MarshalAs(UnmanagedType.String)]
public LPTSTR Lptstr;
}
大概是這樣嗎?
有錯麻煩指正 感謝各位!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 202.39.226.12
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1520237835.A.67D.html
→
03/06 08:10,
6年前
, 1F
03/06 08:10, 1F
→
03/06 08:12,
6年前
, 2F
03/06 08:12, 2F
推
03/06 08:41,
6年前
, 3F
03/06 08:41, 3F