【发布时间】:2017-05-26 01:01:35
【问题描述】:
我正在 Delphi 中创建一个新组件,它实例化一个 DLL
Unit UMyComponent
interface
type
TMyComponent = class(TComponent)
...
procedure MyDllCall;
end;
procedure Register;
implementation
function MyDll: Longint; stdcall; external 'MyDllName.dll' name 'MyFunction'
procedure TMyComponent.MyDllCall;
var
res: LongInt;
begin
res:= MyDll;
end;
...
procedure Register;
begin
RegisterComponents('My Tab', [TMyComponent]);
end;
end.
我有两个问题:
- 当我在 IDE 上安装组件时,它会搜索物理 DLL,如果在路径中找不到它会给出错误。我希望组件在运行时有效使用时查找它。
- 是否可以在运行时设置 dll 库文件名?即:“MyDllName.dll”可以更改为“10029.dll”或“ajjdwawd.dll”
请注意,我将 DLL 声明放在实现中,以免将函数调用暴露给调用者。
感谢您的回答。
【问题讨论】:
-
LoadLibrary + GetProcAddress
-
使用runtime linking(
LoadLibrary、GetProcAddress、FreeLibrary)或delay loading(delayed)。 -
知道了,谢谢。欣赏。
-
使用延迟和工作就像一个魅力。要在运行时更改 dll 名称,恐怕我必须使用 LoadLibrary。谢谢大家。
-
如果您有新问题,请单击顶部的 按钮并编写新问题。编辑新信息以便在回答此问题后提出后续问题是不合适的。我已相应地回滚了您的编辑。
标签: delphi dll components