If fuzzy.dll
exports a function fuzzy_hash_buf
with the C declaration
int fuzzy_hash_buf(unsigned char *buf, uint32_t buf_len, char *result);
then you are right that the Delphi declaration would be
function fuzzy_hash_buf(buf: PAnsiChar; buf_len: cardinal; result: PAnsiChar):
integer;
To use this in Delphi, in the interface
section of a unit, write
function fuzzy_hash_buf(buf: PAnsiChar; buf_len: cardinal; result: PAnsiChar):
integer; stdcall;
Then, in the implementation
section of the very same unit, you do not implement the function yourself, but rather point to the external DLL:
function fuzzy_hash_buf; external 'fuzzy.dll' name 'fuzzy_hash_buf`
Notice that you do not have to redeclare the parameters, the result type, and the calling convention (stdcall
).
Now you can use this function as if it were an actual function of this unit. For instance, you might write
val := fuzzy_hash_buf(buf, len, output);
from any unit that uses
the unit in which you declared fuzzy_hash_buf
.
Update
I am afraid that I am not familiar enough with the CreateFileMapping function. However, after reading the MSDN documentation, I believe that you can do
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.