我想使用来自 ssdeep ( http://ssdeep.sourceforge.net/ ) 的 dll。 API 是:
int fuzzy_hash_buf(unsigned char *buf, uint32_t buf_len, char *result);
然后在Delphi中,我这样写:
function fuzzy_hash_buf(buf : Pbyte; buf_len : Cardinal; result : PAnsiChar): integer;标准调用;外部“fuzzy.dll”名称“fuzzy_hash_buf”;
如何在Delphi中使用该函数?
谢谢!
最佳答案
如果 fuzzy.dll
使用 C 声明导出函数 fuzzy_hash_buf
int fuzzy_hash_buf(unsigned char *buf, uint32_t buf_len, char *result);
那么你是对的,Delphi 声明是
function fuzzy_hash_buf(buf: PAnsiChar; buf_len: cardinal; result: PAnsiChar):
integer;
要在 Delphi 中使用它,请在单元的 interface
部分中编写
function fuzzy_hash_buf(buf: PAnsiChar; buf_len: cardinal; result: PAnsiChar):
integer; stdcall;
然后,在同一单元的implementation
部分,您不自己实现函数,而是指向外部DLL:
function fuzzy_hash_buf; external 'fuzzy.dll' name 'fuzzy_hash_buf`
请注意,您不必重新声明参数、结果类型和调用约定 (stdcall
)。
现在您可以像使用 native 的实际功能一样使用此功能。例如,你可以写
val := fuzzy_hash_buf(buf, len, output);
来自使用
您在其中声明fuzzy_hash_buf
的单元的任何单元。
更新
恐怕我对CreateFileMapping还不够熟悉功能。不过,看完MSDN文档后,我相信你可以做到
var
buf: PAnsiChar;
buf := MapViewOfFile(FFileMappingHandle, FILE_MAP_READ, 0, 0, 0);
// Now, if I have understood MapViewOfFile correctly, buf points to the first byte of the file.
var
StatusCode: integer;
TheResult: PAnsiChar;
GetMem(TheResult, FUZZY_MAX_RESULT);
StatusCode := fuzzy_has_buf(buf, FFileSize, TheResult);
// Now TheResult points to the first byte (character) of the output of the function.
关于c++ - 在 Delphi 2010 中使用 C/C++ DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3557398/