你会如何声明DLL导入签名?

dan*_*die 6 .net c# c++ dllimport

这是使用.NET的pHash的后续帖子

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

int ph_dct_imagehash(const char* file,ulong64 &hash);
Run Code Online (Sandbox Code Playgroud)

到目前为止我有

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

但我现在得到以下错误

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);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

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

Dav*_*nan 11

堆栈不平衡表示C++代码使用,cdecl而您的C#使用stdcall调用约定.把你DLLImport改成这个:

[DLLImport(@"pHash.dll", CallingConvention=CallingConvention.Cdecl)]
Run Code Online (Sandbox Code Playgroud)

C#中的函数签名(返回值和参数)是正确的.