i have created dll file functions , wish reuse in program multiple times in different functions. access-violation error comes after 2nd function of program when calls same dll functions.
i'm using getprocaddress. example:
function xyz:boolean var dllhandle : cardinal; enbfstr : tenbfstr; strtohex : tstrtohex; encodeddata , hexstring : unicodestring; begin dllhandle := loadlibrary('utilities.dll') ; if dllhandle <> 0 begin encodeddata:='sample'; @enbfstr := getprocaddress(dllhandle, 'encodeblowfishstring') ; @strtohex := getprocaddress(dllhandle, 'unistrtounihexstr') ; if assigned (enbfstr) encodeddata:=enbfstr('key','text') ; //sample replaced if assigned (strtohex ) hexstring :=strtohex(encodeddata) ; //call function freelibrary(dllhandle) ; end;
there other functions loading library , calling these dll functions multiple times. also, within same procedure/function, calling these dll functions multiple times in (if else) conditions.
in earlier part of program, have tried check dll file present. also, tried directly load functions 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';
you breaking rules of memory allocation dlls. return value allocated callee deallocated caller. 2 solutions:
- use
sharemem
described in comment @ top of new library project. - use standard interoperability techniques ensure allocation , deallocation happens in same module.
as aside wasteful load , unload dll each time want use it. load dll once only.
furthermore point out encryption operates on binary data , in view storing world of pain working instead text.
Comments
Post a Comment