德尔福2010年使用C / C ++ DLL [英] Using C/C++ DLL in Delphi 2010

查看:153
本文介绍了德尔福2010年使用C / C ++ DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用从ssdeep DLL(http://ssdeep.sourceforge.net/)。 API是:

I want to use dll from ssdeep (http://ssdeep.sourceforge.net/). The API is:

INT fuzzy_hash_buf(无符号字符* buf中,uint32_t的buf_len,字符*结果);

int fuzzy_hash_buf(unsigned char *buf, uint32_t buf_len, char *result);

然后在Delphi中,我把它写这样的:

then in Delp i write it like this:

功能fuzzy_hash_buf(BUF:PBYTE; buf_len:红衣主教;结果:PAnsiChar):整数; STDCALL;外部fuzzy.dll'名'fuzzy_hash_buf';

function fuzzy_hash_buf(buf : Pbyte; buf_len : Cardinal; result : PAnsiChar): integer; stdcall; external 'fuzzy.dll' name 'fuzzy_hash_buf';

如何使用该功能在Delphi?

How to use that function in Delphi?

谢谢!

推荐答案

如果 fuzzy.dll 导出函数 fuzzy_hash_buf 与C声明

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;

要在Delphi中使用此,一个单位中的接口部分,写

To use this in Delp in the interface section of a unit, write

function fuzzy_hash_buf(buf: PAnsiChar; buf_len: cardinal; result: PAnsiChar):
  integer; stdcall;

然后,在实施非常相同的单元部分,您不实现自己的功能,而是指向外部DLL:

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`

请注意,您不必重新声明的参数,结果类型和调用约定( STDCALL )。

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

使用任何单位中,你声明的单元 fuzzy_hash_buf

我害怕,我不与不够熟悉的CreateFileMapping 功能。然而,阅读MSDN文档后,我相信你能做到

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.

这篇关于德尔福2010年使用C / C ++ DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆