首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用来自pHash的.NET

使用来自pHash的.NET
EN

Stack Overflow用户
提问于 2011-06-06 15:36:43
回答 1查看 6.3K关注 0票数 9

我正在尝试使用来自.NET的.NET

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

代码语言:javascript
复制
    [DllImport(@".\Com\pHash.dll")]
    public static extern int ph_dct_imagehash(
        [MarshalAs(UnmanagedType.LPStr)] string file, 
        UInt64 hash);

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

代码语言:javascript
复制
    Unable to find an entry point named 'ph_dct_imagehash' in DLL '.\Com\pHash.dll'.

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

谢谢。

FYI -以下是完整的源代码

代码语言:javascript
复制
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)
            {

            }
        }


    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-07 16:17:00

phash.org上当前的Windows源代码项目(截至7/2011)似乎没有从DLL导出ph_ API调用。您需要通过__declspec(dllexport)在pHash.h行的开头添加这些内容,如下所示:

代码语言:javascript
复制
__declspec(dllexport) int ph_dct_imagehash(const char* file,ulong64 &hash);

然后,您应该使用垃圾箱在DLL中看到导出显示。

代码语言:javascript
复制
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代码会崩溃,所以似乎有一些这里还有更多的工作要做.

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6254447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档