Dll 此WebP C+的正确C#PInvoke签名+;作用
我想为你写一个C#包装 我尝试调用的方法是:Dll 此WebP C+的正确C#PInvoke签名+;作用,dll,interop,pinvoke,webp,Dll,Interop,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 uin
// 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);
借用我的经验,我得出以下结论:
[DllImport("libwebp", CharSet = CharSet.Auto)]
public static extern IntPtr WebPEncodeRGB(IntPtr data, int width, int height, int stride, float quality, ref IntPtr output);
不幸的是,每当我尝试运行此程序时,都会出现以下错误:
调用PInvoke函数“WebPSharpLib!”!LibwebpSharp.Native.WebPEncoder::WebPEncodeRGB'已使堆栈不平衡。这可能是因为托管PInvoke签名与非托管目标签名不匹配。检查PInvoke签名的调用约定和参数是否与目标非托管签名匹配
我在签名上做了很多改动,但都没有用
有人有线索吗
干杯,
迈克 < P>最可能导致错误的原因是C++代码使用了
[DllImport("libwebp", CallingConvention=CallingConvention.Cdecl)]
public static extern UIntPtr WebPEncodeRGB(IntPtr data, int width, int height,
int stride, float quality, ref IntPtr output);
对于没有文本参数的函数,不需要指定CharSet
。我还将使用UIntPtr
作为返回类型,因为size\u t
是无符号的
您的代码可能会有更多问题,因为我们看不到您如何调用函数,也不知道调用函数的协议是什么。为了知道如何调用函数,您需要知道的不仅仅是函数签名。但是,我怀疑调用约定问题会让您克服当前的障碍。删除最后一个
IntPtr
参数上的ref
。@JaredPar:不,不要。这是一个双线程。那些C++代码> int >代码> s?@ Windows C/C++ +Cudio>代码> int >代码32位。事实上,C/C++long
@SLaks也是如此。双指针可以正确编组为IntPtr
。它们大小相同,您可以在托管端的IntPtr
中查找获得它的内部值!把我甩了,因为mc kay的运动鞋上没有Cdecl