1
winapi中的某些結構在每個Windows版本中都有其他成員。P /調用條件結構
typedef struct MyStruct
{
int cbSize;
int a;
int b;
#if _WIN32_WINNT >= 0x0600
int c;
int d;
#endif
} MyStruct, *PMyStruct;
當我端口這對C#是確定以定義所有成員(CBSIZE,A,B,C,d),並通過該結構作爲參數在一些pinvoked功能,還是應該我定義爲XP較小結構?
如果我通過完整的結構與更小的cbSize,不會c,d字段損壞函數的其他參數? WinapiFunc(theStruct,arg2,arg3); – albert
@albert,不,因爲API需要一個指向結構的指針。調用堆棧中唯一的東西是指針值 - 無論指向哪個結構的大小。 p/Invoke定義應該使用'ref struct'來表示這一點。請參閱http://www.pinvoke.net/default.aspx/user32/GetWindowInfo.html和http://msdn.microsoft.com/en-us/library/windows/desktop/ms633516(v=vs.85)。 ASPX – shf301