使用.NET中的pHash

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

我试图从.NET 使用pHash

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

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

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

    Unable to find an entry point named 'ph_dct_imagehash' in DLL '.\Com\pHash.dll'.
Run Code Online (Sandbox Code Playgroud)

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

谢谢.

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

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)
            {

            }
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

rup*_*llo 13

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

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

然后,您应该看到使用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)
Run Code Online (Sandbox Code Playgroud)

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

然而...

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

  • PNG似乎需要一些额外的步骤:http://stackoverflow.com/questions/4001816/loading-pngs-with-cimg (2认同)