gpt4 book ai didi

c# - 你将如何声明 DLL 导入签名?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:15:00 24 4
gpt4 key购买 nike

这是Using pHash from .NET的后续帖子

您将如何在 .NET 中声明以下 C++ 声明?

int ph_dct_imagehash(const char* file,ulong64 &hash);

到目前为止我有

[DllImport(@"pHash.dll")]
public static extern int ph_dct_imagehash(string file, ref ulong hash);

但是我现在遇到以下错误

ulong hash1 = 0, hash2 = 0;
string firstImage = @"C:\Users\dance2die\Pictures\2011-01-23\177.JPG";
string secondImage = @"C:\Users\dance2die\Pictures\2011-01-23\176.JPG";
ph_dct_imagehash(firstImage, ref hash1);
ph_dct_imagehash(secondImage, ref hash2);

enter image description here

它基本上是说我对 ph_dtc_imagehash 的声明是错误的。
我在这里做错了什么?

最佳答案

堆栈不平衡表示 C++ 代码使用 cdecl 而您的 C# 使用 stdcall 调用约定。将您的 DLLImport 更改为:

[DLLImport(@"pHash.dll", CallingConvention=CallingConvention.Cdecl)]

C# 中的函数签名(返回值和参数)在其他方面是正确的。

关于c# - 你将如何声明 DLL 导入签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6309237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com