What are the limitations on marshalling types via P/Invoke?
• 返回值 • 只能是长度小于等于32位的类型 • 非浮点型not floating point • 参数 • Only support marshaling blittable types • blittable types -> same representation in memory in both managed and native • non-blittable -> memory transformation required • Since only blittable types, all objects are pinned and never copied • Exception: passing String ByVal in VB.NET • Implies that you can’t marshal nested objects since this requires a memory transformation (non-blittable) • 只能是长度小于等于32位的类型 • 值通过堆栈传递 • 例外:float32 • 参考(References) • Pass blittable reference types • 把参考传递到值类型变量 • 这就是如何传递float32类型的值 • 可以传递值类型的数组 • 在本地代码中,您可以使用指针指向第一个对象,然后一个接一个地访问其他对象 • String是特殊的,传递char数组 -> 不变的 • StringBuilder是特殊的,传递char数组 -> 易变的 (需要单独传递长度) • 注意:C# bool是8个比特位的,并且不等于Win32的BOOL • 队列:编译器默认的队列 (4字节) • Marshal.GetLastWin32Error 支持 GetLastError() 语义 • 未支持的: • MarshalAs: no support for non-blittable types • StructLayout: 不能改变外观 • Delegates(委托) • DateTime • Only support default calling convention 6.11. 调用GetLastError时,总是获得不定的代码? 尽量不要尝试调用Window