我试图编写一个C#包装Google's WebP encoder。正确的C#PInvoke签名此WebP C++函数
的方法我尝试打电话是:
// Returns the size of the compressed data (pointed to by *output), or 0 if
// an error occurred. The compressed data must be released by the caller
// using the call 'free(*output)'.
WEBP_EXTERN(size_t) WebPEncodeRGB(const uint8_t* rgb,
int width, int height, int stride,
float quality_factor, uint8_t** output);
借用mc-kay's decoder wrapper我想出了以下内容:
[DllImport("libwebp", CharSet = CharSet.Auto)]
public static extern IntPtr WebPEncodeRGB(IntPtr data, int width, int height, int stride, float quality, ref IntPtr output);
不幸的是,每当我试图运行此我得到以下错误:
A call to PInvoke function 'WebPSharpLib!LibwebpSharp.Native.WebPEncoder::WebPEncodeRGB' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
我已经尝试了许多变化的签名到无avai湖
任何人都有线索?
干杯, 迈克
删除最终的'IntPtr'参数上的'ref'。 – JaredPar 2012-03-13 23:13:41
@JaredPar:不,不要。这是一个双重指针。 – SLaks 2012-03-13 23:14:34
这些C++'int'的大小是多少? – SLaks 2012-03-13 23:15:00