【发布时间】:2012-10-09 14:20:51
【问题描述】:
据我了解,MarshalAsAttribute(UnmanagedType.SysUInt) 应该将特定于平台的无符号整数类型(32 或 64 字节)编组为托管类型 (ulong)。
/// Return Type: size_t->unsigned int
///bgr: uint8_t*
///width: int
///height: int
///stride: int
///output: uint8_t**
[DllImportAttribute("libwebp.dll", EntryPoint = "WebPEncodeLosslessBGR")]
[return: MarshalAsAttribute(UnmanagedType.SysUInt)]
public static extern ulong WebPEncodeLosslessBGR([InAttribute()] IntPtr bgr, int width, int height, int stride, ref IntPtr output);
但它不起作用 - 我收到此错误:
Cannot marshal 'return value': Invalid managed/unmanaged type combination (Int64/UInt64 must be paired with I8 or U8).
我知道I can switch the return type to IntPtr,但这对于使用我的 API 的人来说是非常不直观的。
为什么 SysUInt 不工作?
【问题讨论】:
-
UIntPtr肯定是正确的类型。为什么要ulong? -
语义,它是一个公共 API。
-
您可以在公共 API 中使用 size_t
-
.Net 没有 size_t 类型,是吗?
标签: c# pinvoke marshalling