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

标签 c# .net c++ dllimport

这是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/

相关文章:

c# - 您能否以编程方式与基于组件的服务 (TrustedInstaller) 交互?

c++ - 为什么继承的函数会忽略在原始函数中调用的重写函数?

c# - 将匿名类型的对象作为参数传递给方法

c#:使第 3 方对象可序列化

c# - 依赖注入(inject)容器?它有什么作用?

c# - 如何解析类型为 'IdentityServer4.EntityFramework.Options.OperationalStoreOptions' 的服务

c# - 有没有更好的方法从另一个类(class)获取信息?

c# - 如何暂停 Threading.timer 以完成功能

C# VSTO 加载项 - 将纯文本电子邮件转换为 HTML

c++ - 减少类模板专门化中的代码重复 (array<Unique_ptr>)