Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dll 此WebP C+的正确C#PInvoke签名+;作用_Dll_Interop_Pinvoke_Webp - Fatal编程技术网

Dll 此WebP C+的正确C#PInvoke签名+;作用

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

我想为你写一个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);
借用我的经验,我得出以下结论:

[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++代码使用了 CCDL> 调用约定,但是您的pCuNKE使用了<代码> STDCALL> /COD>调用约定。按如下方式更改pinvoke:

[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