如果 fuzzy.dll 导出带有 C 声明的函数 fuzzy_hash_buf
int fuzzy_hash_buf(unsigned char *buf, uint32_t buf_len, char *result);
那么你是对的,德尔福声明是
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)。
现在您可以像使用本机的实际功能一样使用此功能。例如,你可以写
val := fuzzy_hash_buf(buf, len, output);
来自uses 声明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.