这是Using pHash from .NET的后续文章。
如何在C++声明后在.NET中声明?
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);

它基本上说我对ph_dtc_imagehash的声明是错误的。
,我在这里做错什么了?
发布于 2011-06-10 16:39:33
堆栈不平衡表示C++代码使用cdecl,而C#使用stdcall调用约定。将您的DLLImport更改为:
[DLLImport(@"pHash.dll", CallingConvention=CallingConvention.Cdecl)]否则,C# (返回值和参数)中的函数签名是正确的。
发布于 2011-06-10 16:35:59
查一下电话会议。如果没有在DllImport属性上指定一个属性,则默认为WinApi (stdcall)。您发布的C代码段没有指定调用约定,至少在VC++中默认的调用约定是cdecl。
所以你应该试试:
[DllImport(@"pHash.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern int ph_dct_imagehash(string file, ref ulong hash);发布于 2011-06-10 16:29:48
尝试显式地将DllImportAttribute.CharSet属性设置为CharSet.Auto,就好像您没有指定它一样,它将默认为Ansi。这可能会引起问题,因为你的声明似乎是好的。
即使这不是问题,习惯于在Dll函数处理文本时指定CharSet属性。
https://stackoverflow.com/questions/6309237
复制相似问题