使用.NET的pHash

我试图从.NET使用pHash

我尝试的第一件事是注册(regsvr32) phash.dll并在这里询问其次,我试图使用DllImport导入,如下所示。

  [DllImport(@".\Com\pHash.dll")] public static extern int ph_dct_imagehash( [MarshalAs(UnmanagedType.LPStr)] string file, UInt64 hash); 

但是当我尝试在运行时访问上述方法时,会显示以下错误消息。

  Unable to find an entry point named 'ph_dct_imagehash' in DLL '.\Com\pHash.dll'. 

“切入点”是什么意思,为什么我会收到错误?

谢谢。

仅供参考 – 这是完整的源代码

 using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows; namespace DetectSimilarImages { public partial class MainWindow : Window { [DllImport(@".\Com\pHash.dll")] public static extern int ph_dct_imagehash( [MarshalAs(UnmanagedType.LPStr)] string file, UInt64 hash); public MainWindow() { InitializeComponent(); Loaded += MainWindow_Loaded; } void MainWindow_Loaded(object sender, RoutedEventArgs e) { try { UInt64 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, hash1); ph_dct_imagehash(secondImage, hash2); Debug.WriteLine(hash1); Debug.WriteLine(hash2); } catch (Exception ex) { } } } } 

phash.org上当前的Windows源代码项目(截至2011年7月)似乎没有从DLL导出ph_API调用。 您需要在pHash.h中的行开头用__declspec(dllexport)自己添加这些,如下所示:

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

然后,您应该使用dumpbin看到导出显示在DLL中

 dumpbin /EXPORTS pHash.dll ... Dump of file pHash.dll ... 1 0 00047A14 closedir = @ILT+2575(_closedir) 2 1 00047398 opendir = @ILT+915(_opendir) 3 2 00047A4B ph_dct_imagehash = @ILT+2630(_ph_dct_imagehash) 4 3 000477B2 readdir = @ILT+1965(_readdir) 5 4 00047A00 rewinddir = @ILT+2555(_rewinddir) 6 5 000477AD seekdir = @ILT+1960(_seekdir) 7 6 00047AFA telldir = @ILT+2805(_telldir) 

您现在应该能够使用C#中的此调用。

然而…

当我尝试调用它时,我在CImg代码中崩溃了,所以似乎还有一些工作要做 …