简体   繁体   中英

How to register a 64-bit dll (on a 64-bit OS) from a 32-bit application

I currently use the following function to register a dll that handles context menu calls.

function RegisterLibrary(szLibrary: String): Integer;
var
  hLib: THandle;
  drs: TDllRegisterServer;
begin
  // Attempt to load the library
  hLib := LoadLibrary(PChar(szLibrary));

  // Handle check
  if IsHandle(hLib) then
  begin // Get the register function
    @drs := GetProcAddress(hLib, LIB_REGISTER);

    if Assigned(@drs)
      then Result := drs            // Make the function call
      else Result := GetLastError;  // Return last error

    // Unload the library
    FreeLibrary(hLib);
  end else
    Result := GetLastError; // Return last error
end;

Unfortunately it doesn't work when trying to register a 64-bit dll from my 32-bit application.

Is there any alternative to register my 64-bit dll (compiled with free pascal) from my 32-bit application (compiled in Delphi)?

I suppose I can call C:\\Windows\\system\\regsvr32.exe" /s "filename" but would like to know if I have any other alternative.

Thanks!

No, a 32 bits process can not load a 64 bit dll. You would have to go with calling a 64 bits process that registers the dll for you.

You will have to use a 64 bit process to perform the registration, as the 32 bit Delphi program can't load a 64 bit DLL into its address space.

If you don't want to write the code yourself then you can have a look at the Inno Setup source code. There is a Visual Studio project for the 64 bit helper app, and the unit Helper.pas has the code to call the external helper, so you can simply use the HelperRegisterTypeLibrary() function it contains.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM