I have created a DLL file with some functions and wish to reuse in a program multiple times in its different functions. But the Access-violation error comes after 2nd function of the program when calls the same DLL functions.
I'm currently using GetProcAddress. For example:
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;
There are other functions which is loading the library and calling these DLL functions multiple times. Also, within the same procedure/function, we are calling these DLL functions multiple times in (IF Else) conditions.
In earlier part of the program, I have tried to check for the DLL file is present. Also, I tried to directly load the functions as another alternative:
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';