對於PInvoke的來電顯式佈局我需要一個結構相當於說以下內容:結構與LPWSTR和結構
typedef struct _Somenativestruct {
PCWSTR filename;
DWORD count;
DWORD anothercount;
AnEnumWithByteSize info;
union {
Structwithoneintfield Progress;
Anotherstructwithoneintfield Result;
};
} Somenativestruct , *PSomenativestruct ;
因爲它有一個工會的結構我必須使它layout.explicit但問題是我將爲PCWSTR的文件名所做的偏移量是多少。 由於它的32位指針可以提供4的偏移量?以下是正確的嗎?
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
public struct Mynet40struct
{
[FieldOffset(0)]
private [MarshalAs(UnmanagedType.LPWStr)] string filename;
[FieldOffset(4)]
private int count;
[FieldOffset(8)]
private int anothercount;
[FieldOffset(12)]
AnEnumWithByteSize info;
[FieldOffset(13)]
StructWithOneIntField progress;
[FieldOffset(13)]
AnotherStructWithOneIntField result;
}