如何声明DLL的导入签名? [英] How would you declare DLL import signature?
本文介绍了如何声明DLL的导入签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何声明如下C ++声明.NET?
How would you declare following C++ declaration in .NET?
int ph_dct_imagehash(const char* file,ulong64 &hash);
到目前为止,我
So far i have
[DllImport(@"pHash.dll")]
public static extern int ph_dct_imagehash(string file, ref ulong hash);
不过,我现在收到以下错误
But I am now getting following error for
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的declartion是错误的。
我在做什么错在这里?
It basically says that my declartion of ph_dtc_imagehash is wrong.
What am I doing wrong here?
推荐答案
堆栈失衡表明,C ++ code使用 CDECL
和你的C#使用 STDCALL
调用约定。改变你的的DllImport
来这样的:
Stack imbalance indicates that the C++ code uses cdecl
and your C# uses stdcall
calling convention. Change your DLLImport
to this:
[DLLImport(@"pHash.dll", CallingConvention=CallingConvention.Cdecl)]
在C#(返回值和参数)的函数签名,否则正确的。
The function signature in C# (return value and parameters) is otherwise correct.
这篇关于如何声明DLL的导入签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文