Jump to content
boris.nihil

openssl dll problem

Recommended Posts

hello

is it possible to have 2 or more version of the same dll in application? (ssleay32.dll and libeay32.dll)

i have some old unit whitch uses openssl dlls from 2005 and i am sending emails with Indy which required openssl dlls from 2019...

i have set a path for Indy dlls at the program start, initialisation, sslpath...

 

when i use loadlibrary('') for this 2005. year dll, i cannot send emails enymore with indy, it say 

"the ordinal 3844 could not be located in the dynamic link library"

 

Share this post


Link to post
1 hour ago, boris.nihil said:

hello

is it possible to have 2 or more version of the same dll in application? (ssleay32.dll and libeay32.dll)

i have some old unit whitch uses openssl dlls from 2005 and i am sending emails with Indy which required openssl dlls from 2019...

i have set a path for Indy dlls at the program start, initialisation, sslpath...

 

when i use loadlibrary('') for this 2005. year dll, i cannot send emails enymore with indy, it say 

"the ordinal 3844 could not be located in the dynamic link library"

 

You could try to rename the DLLs. I'm not sure whether this will work though. And if it works, it will only do so for DLLs that are used by your program directly, not for DLLs that are loaded by other DLLs your program uses.

Share this post


Link to post

You can't normally have multiple versions of the DLLs with the same file names loaded at the same time. But, in this case, you can't just rename the DLLs either, because IIRC one of them depends on the other using the original filename. 

 

You could try wrapping the old unit code inside of an Activation Context so it can use the older DLLs while the rest of your app uses the newer DLLs. But, this is a pretty advanced technique. 

 

Otherwise, if you can't update the older unit to use the newer DLLs, then you will probably be best off splitting the two codes into separate EXEs with different DLL dependancies. 

Edited by Remy Lebeau

Share this post


Link to post
Just now, Remy Lebeau said:

You can't normally have multiple versions of the DLLs with the same file names loaded at the same time.

As far as I know, Windows loads DLLs without checking if the module is already loaded in memory ONLY if the DLLs are "pointed" with the full path.

So in his case one of the solutions I see is that his program loads the 2005 DLLs of your old modules first and then the new ones of 2019 with Indy with the full path (maybe with the new DLLs in a directory outside the system path).

He must therefore prevent Indy from loading its libraries first.

 

Was there (from memory) the possibility of loading Indy DLLs in a delayed way ?

Share this post


Link to post

You can try loading the correct version of the DLL at the start of each application using something like this (place this unit as the first unit in the uses section of your .dpr file):

 

unit loadssldll;

interface

uses
  Windows,
  System.IOUtils,
  System.Types,
  System.SysUtils;

implementation

uses
  SvcMgr,
  avglobal,
  avfiles;

procedure LoadOpenSSLDll;
var
  libHandle: array of cardinal;
  dllpath: string;
  fName: string;
  poz: integer;
begin
{$IFDEF WIN32}
  dllpath := GlobalRootPath + 'OpenSSL_32';
{$ELSE}
  dllpath := GlobalRootPath + 'OpenSSL_64';
{$ENDIF}
  SetDllDirectory(PWideChar(dllpath));
  poz := 0;
  for fName in TDirectory.GetFiles(System.SysUtils.IncludeTrailingPathDelimiter(dllpath), '*.dll')  do
  begin
    if (ExtractFileExt(fName) <> '.dll') then // make sure that .dll
      Continue
    else
    begin
      Inc(poz);
      SetLength(libHandle, poz);
      libHandle[poz-1] := LoadLibrary(PWideChar(TPath.GetFileName(fname)));
      if (libHandle[poz-1] = 0) then
      begin
        with TEventLogger.Create(globalAppName) do
        begin
          try
            LogMessage('ERROR (loadssldll.LoadOpenSSLDll): ' + dllpath + ' cannot be loaded.', EVENTLOG_ERROR_TYPE);
          finally
            Free;
          end;
        end;
        Halt(1); // the libs aren't found, terminate
      end;
    end;

  end;
  SetDllDirectory(nil);
end;


initialization
   LoadOpenSSLDll;

end.

 

 

Share this post


Link to post
1 hour ago, ioan said:

You can try loading the correct version of the DLL at the start of each application using something like this (place this unit as the first unit in the uses section of your .dpr file):

 

i think this will not work...

 

But why application cant free dll previously loaded with

     

Handle := LoadLibrary(pchar(ExtractFilePath(Application.ExeName)+ 'ssl_old\DLL-2005\libeay32.dll'));

with freelybrary

FreeLibrary(Handle);
          Handle := 0;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×