耗时ç的DLL德尔福

编程入门 行业动态 更新时间:2024-10-10 08:23:40
本文介绍了耗时ç的DLL德尔福的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个签名的DLL函数:

I have a Dll function with this signature:

UInt32 Authenticate(uint8 *Key);

我对德尔福这样做的:

I'm doing this on Delphi:

function Authenticate(Key:string) : UInt32; external 'mylib.dll' name 'Authenticate';

但始终,函数返回10(错误code)和应用刹车:\\

But always, the function return 10 (error code) and the application brakes :\

有一种方法可以做到这一点吧?

There is a way to do this right?

更新: 谢谢你们!你是最棒的!的

推荐答案

有一些问题,你的code。

There are some problems with your code.

1) UINT8 是字节在Delphi中,没有字符串。

1) uint8 is the equivilent of Byte in Delp not String.

2)C code为使用编译器的默认调用约定,这通常是 __ CDECL 。德尔福的默认调用约定,在另一方面,是注册来代替。它们并不互相兼容。如果不匹配的调用约定,堆栈和CPU寄存器将不能正确运行时函数调用期间管理的。

2) the C code is using the compiler's default calling convention, which is usually __cdecl. Delphi's default calling convention, on the other hand, is register instead. They are not compatible with each other. If you mismatch the calling convention, the stack and CPU registers will not be managed correctly during the function call at runtime.

在C code的字面翻译就是这个:

A literal translation of the C code would be this instead:

function Authenticate(Key: PByte) : UInt32; cdecl; external 'mylib.dll';

然而,假设该函数实际上是期待一个空终止字符串,然后做这个:

However, assuming the function is actually expecting a null-terminated string then do this instead:

// the function is expecting a pointer to 8-bit data, // so DO NOT use `PChar`, which is 16-bit in Delphi 2009+... function Authenticate(Key: PAnsiChar) : UInt32; cdecl; external 'mylib.dll';

我要坚持第一个声明,因为它原来的C code相匹配。即使函数需要一个空值终止字符串作为输入,您还可以通过它使用 PBYTE 通过类型转换:

var S: AnsiString; begin Authenticate(PByte(PAnsiChar(S))); end;

或者,如果功能允许空值输入空字符串:

Or, if the function allows NULL input for empty strings:

var S: AnsiString; begin Authenticate(PByte(Pointer(S))); end;

更多推荐

耗时ç的DLL德尔福

本文发布于:2023-10-26 06:32:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529355.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:德尔福   DLL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!