C# 使用.NET中的pHash
我正在尝试从.NET使用 我尝试的第一件事是注册(regsvr32)C# 使用.NET中的pHash,c#,.net,c++,dllimport,C#,.net,C++,Dllimport,我正在尝试从.NET使用 我尝试的第一件事是注册(regsvr32)phash.dll并询问 其次,我尝试使用如下所示的方式导入 [DllImport(@".\Com\pHash.dll")] public static extern int ph_dct_imagehash( [MarshalAs(UnmanagedType.LPStr)] string file, UInt64 hash); 但当我在运行时尝试访问上述方法时,会显示以下错误
phash.dll
并询问
其次,我尝试使用如下所示的方式导入
[DllImport(@".\Com\pHash.dll")]
public static extern int ph_dct_imagehash(
[MarshalAs(UnmanagedType.LPStr)] string file,
UInt64 hash);
但当我在运行时尝试访问上述方法时,会显示以下错误消息。 Unable to find an entry point named 'ph_dct_imagehash' in DLL '.\Com\pHash.dll'.
“入口点”是什么意思?为什么我会出错
多谢各位
仅供参考-以下是完整的源代码
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)
{
}
}
}
}
上的当前Windows源代码项目(截至2011年7月)似乎没有从DLL导出PHAPI调用。您需要在pHash.h中的行开始处通过uu declspec(dllexport)自己添加这些,如下所示:
__declspec(dllexport) int ph_dct_imagehash(const char* file,ulong64 &hash);
然后,您应该会看到导出显示在DLL中,使用
您现在应该可以从C#使用此呼叫
然而
当我尝试调用此函数时,CImg代码中出现了崩溃,因此似乎有一些…是您自己编译DLL的吗?如果是的话,你是否注意正确地导出相关函数?”康拉德:我自己编译了这个源码,但是我失去了你说的“适当导出相关函数”,因为我根本不熟悉C++……宋,然后修复很容易:不要自己编译库。使用预编译的二进制文件。不幸的是,我仍然无法解析
在DLL.\Com\pHash.DLL中找不到名为“ph\u dct\u imagehash”的入口点。
eror即使使用预编译的dlls@ildjam:谢谢你提到这件事。我也不确定,所以我联系了pHash开发人员,他告诉我DllImport语句应该类似于[DllImport(“pHash”,CharSet=CharSet.Ansi)]公共静态外部int ph\u dct\u imagehash(string file,ref-ulong hash)代码>这在png_read_info()中对我来说崩溃了,但对于JPGsPNG来说似乎工作正常似乎需要一些额外的步骤:在执行dumpbin之后,我能够看到'3 2 00047A4B ph_dct_imagehash=@ILT+2630(_ph_dct_imagehash'),但我仍然无法dllimport phash.dll。这里发生的事情是,我没有完全依赖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)