从.NET中使用pHash [英] Using pHash from .NET

查看:1051
本文介绍了从.NET中使用pHash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 pHash 从.NET

首先我想是注册(REGSVR32) phash.dll ,问<一href="http://stackoverflow.com/questions/6233343/how-to-add-unmanaged-dll-to-show-up-in-add-references-com-tab">here 所有第二,我试图用导入<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx">DllImport如下所示。

  [的DllImport(@。\的COM \ pHash.dll)
    公共静态外部INT ph_dct_imagehash(
        [的MarshalAs(UnmanagedType.LPStr)字符串的文件,
        UINT64哈希);
 

但是,当我尝试在运行时访问上面的方法,以下错误消息出现了。

 无法找到名为ph_dct_imagehash在DLL中的入口点。\的COM \ pHash.dll。
 

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

感谢你。

仅供参考 - 下面是完整的源代码code

 使用系统;
使用System.Diagnostics程序;
使用了System.Runtime.InteropServices;
使用System.Windows;

命名空间DetectSimilarImages
{
    公共部分类主窗口:窗口
    {
        [的DllImport(@。\的COM \ pHash.dll)
        公共静态外部INT ph_dct_imagehash(
            [的MarshalAs(UnmanagedType.LPStr)字符串的文件,
            UINT64哈希);


        公共主窗口()
        {
            的InitializeComponent();

            加载+ = MainWindow_Loaded;
        }

        无效MainWindow_Loaded(对象发件人,RoutedEventArgs E)
        {
            尝试
            {
                UINT64 HASH1 = 0,HASH2 = 0;
                字符串firstImage = @C:\ Users \用户dance2die \图片\ 2011-01-23 \ 177.JPG;
                字符串secondImage = @C:\ Users \用户dance2die \图片\ 2011-01-23 \ 176.JPG;
                ph_dct_imagehash(firstImage,HASH1);
                ph_dct_imagehash(secondImage,HASH2);

                的Debug.WriteLine(HASH1);
                的Debug.WriteLine(HASH2);
            }
            赶上(例外前)
            {

            }
        }


    }
}
 

解决方案

目前的Windows源$ C ​​$ C项目(为7/2011)上的 phash.org 似乎没有出口从DLL ph_ API调用。您将需要通过__declspec(dllexport)的在该行的pHash.h像这样的开头添加这些自己:

  __ declspec(dllexport)的INT ph_dct_imagehash(为const char *文件,ulong64和放大器;散);
 

使用之后,应看到出口出现在DLL DUMPBIN

  DUMPBIN / EXPORTS pHash.dll
...
转储文件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 code崩溃,所以似乎有一些的更多的工作要做这里 ...

I am trying to use pHash from .NET

First thing I tried was to register (regsvr32) phash.dll and asked here Second of all, i was trying to import using DllImport as shown below.

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

But when i try to access the method above during run-time, following error message shows up.

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

What does "entry point" means and why am I getting the error?

Thank you.

FYI - Here is the full source code

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

            }
        }


    }
}

解决方案

The current Windows source code project (as of 7/2011) on phash.org does not seem to export the ph_ API calls from the DLL. You will need to add these yourself by __declspec(dllexport) at the beginning of the line in pHash.h like so:

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

You should then see the export show up in the DLL using dumpbin

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)

You should now be able to use this call from C#.

however...

I am getting a crash in the CImg code when I try to call this, so it seems there is some more work to do here...

这篇关于从.NET中使用pHash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆