Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using pHash from .NET

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

            }
        }


    }
}
like image 221
dance2die Avatar asked Jun 06 '11 15:06

dance2die


1 Answers

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

like image 102
rupello Avatar answered Nov 14 '22 14:11

rupello