gpt4 book ai didi

delphi - 使用 dll 的接口(interface)安全吗

转载 作者:行者123 更新时间:2023-12-03 15:22:33 25 4
gpt4 key购买 nike

当我想导出 DLL 中的类时,从接口(interface)派生它并通过导出函数返回该接口(interface)是正确的方法吗?

//exported dll function, which is used in the exe.
function MyClass_Create: IMyClass;
begin
result := TMyClass.Create;
end;

内存管理怎么样?我可以传入/传出不同的接口(interface)和字符串而不必担心和崩溃吗?

IMyClass = interface
procedure SetString(aMsg: string);
function GetString: string;

procedure SetClass(aClass: ITestClass);
function GetClass: ITestClass;
end;

最佳答案

接口(interface)引用与内存管理正交。通常你导出一个从dll返回接口(interface)引用的函数,并且不关心内存管理。通过引用计数接口(interface),您可以确保实现接口(interface)的对象实例也将在 dll 中被释放。

字符串不同。无论您导出接口(interface)还是导出平面函数并不重要 - 都适用相同的限制。

顺便说一句,您的问题标题不正确,Delphi 中没有“接口(interface)实例”。

关于delphi - 使用 dll 的接口(interface)安全吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8846545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com