Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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(@".CompHash.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 '.CompHash.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(@".CompHash.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:Usersdance2diePictures2011-01-23177.JPG";
                string secondImage = @"C:Usersdance2diePictures2011-01-23176.JPG";
                ph_dct_imagehash(firstImage, hash1);
                ph_dct_imagehash(secondImage, hash2);

                Debug.WriteLine(hash1);
                Debug.WriteLine(hash2);
            }
            catch (Exception ex)
            {

            }
        }


    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
345 views
Welcome To Ask or Share your Answers For Others

1 Answer

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...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...