title: Call and Reuse the DLL functions dynamically
body: <p>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. </p>
  
  <p>I'm currently using GetProcAddress. For example:</p>
  
  <pre><code>function xyz:boolean
  var
     dllHandle : cardinal;
     EnBFStr : TEnBFStr;
     StrToHex : TStrToHex;
     Encodeddata , HexString : UnicodeString;
  
     begin
       dllHandle := LoadLibrary('Utilities.dll') ;
       if dllHandle &lt;&gt; 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;
  </code></pre>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>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';
  </code></pre>