【发布时间】:2016-08-01 16:41:46
【问题描述】:
我创建了一个包含一些功能的 DLL 文件,并希望在一个程序的不同功能中多次重用。但是当调用相同的 DLL 函数时,访问冲突错误出现在程序的第二个函数之后。
我目前正在使用 GetProcAddress。例如:
function xyz:boolean
var
dllHandle : cardinal;
EnBFStr : TEnBFStr;
StrToHex : TStrToHex;
Encodeddata , HexString : UnicodeString;
begin
dllHandle := LoadLibrary('Utilities.dll') ;
if dllHandle <> 0 then
begin
Encodeddata:='Sample';
@EnBFStr := GetProcAddress(dllHandle, 'EncodeBlowFishString') ;
@StrToHex := GetProcAddress(dllHandle, 'UniStrToUniHexStr') ;
if Assigned (EnBFStr) then
Encodeddata:=EnBFStr('Key','Text') ; //Sample would be replaced
if Assigned (StrToHex ) then
HexString :=StrToHex(Encodeddata) ; //call the function
FreeLibrary(dllHandle) ;
end;
还有其他函数正在加载库并多次调用这些 DLL 函数。此外,在同一个过程/函数中,我们在 (IF Else) 条件下多次调用这些 DLL 函数。
在程序的早期部分,我尝试检查是否存在 DLL 文件。另外,我尝试直接加载函数作为另一种选择:
function EncodeBlowFishString (Const Key:UnicodeString; Const DecodedString:UnicodeString; ): UnicodeString; stdcall;
external 'Utilities.dll' name 'EncodeBlowFishString';
function UniStrToUniHexStr(Const aString:UnicodeString): UnicodeString; stdcall;
external 'Utilities.dll';
【问题讨论】: