Delphi BPL无法动态加载64位包

Delphi BPL无法动态加载64位包,delphi,bpl,Delphi,Bpl,当应用程序和库都编译为64位时,动态加载库时出现问题 声明如下: intHandle: = LoadPackage (PWideChar (strFileName)); 导致以下错误: Project Project1.exe引发异常类EPackageError,消息为“无法加载包F:\New Projects\bpls\exe\Win64\Debug\libs\MinhaLib.bpl. %1不是有效的Win32应用程序“” 如果我将应用程序和库重新编译为32位,那么一切都可以完美地工作 我

当应用程序和库都编译为64位时,动态加载库时出现问题

声明如下:

intHandle: = LoadPackage (PWideChar (strFileName));
导致以下错误:

Project Project1.exe引发异常类EPackageError,消息为“无法加载包F:\New Projects\bpls\exe\Win64\Debug\libs\MinhaLib.bpl.
%1不是有效的Win32应用程序“”

如果我将应用程序和库重新编译为32位,那么一切都可以完美地工作

我将我的库更改为DLL,并使用
LoadLibrary()
函数。在这个场景中,所有内容在32位和64位中都能完美工作

要使BPL库在64位中工作,我必须对其进行任何更改吗

我使用的是Delphi10.3

项目1.dpr:

program Project1;

{$APPTYPE CONSOLE}
{$R *.res}

uses
   System.SysUtils, Winapi.Windows;

type
   TMyFunc = function(const intA, intB: Integer): Integer; stdcall;

begin
   try
      var myLib := ExtractFilePath(ParamStr(0)) + 'Lib.bpl';
      var intHandle := LoadPackage(myLib);
      try
         if intHandle <> 0 then
         begin
            var myFnc: TMyFunc := GetProcAddress(intHandle, PWideChar('MyFunction'));
            if @myFnc <> nil then
               Writeln('Result: ', myFnc(5, 5));
         end;

         var strV: string := '';
         Readln(strV);
      finally
         if intHandle <> 0 then
            UnloadPackage(intHandle);
      end;

   except
      on E: Exception do
         Writeln(E.ClassName, ': ', E.Message);
   end;

end.
单元1.pas:

unit Unit1;

interface

function MyFunction(const intA, intB: Integer): Integer; stdcall;

implementation

function MyFunction(const intA, intB: Integer): Integer;
begin
   Result := intA + intB;
end;

exports
   MyFunction;

end.

所讨论的错误是
error\u BAD\u EXE\u FORMAT
,通常在32位进程尝试加载64位DLL或64位进程尝试加载32位DLL时发生。您的库是否依赖于另一个64位不可用的库?可能在编译为BPL时动态链接到该库,但在编译为DLL时静态链接?在不知道实际设置的情况下回答您的问题是否很困难。@RemyLebeau您在哪里看到此错误:error\u BAD\u EXE\u FORMAT?“您在哪里看到此错误:error\u BAD\u EXE\u FORMAT”-这是文本消息
“%1不是有效的Win32应用程序”
。调试器将以这种格式向您显示一条弹出消息:
“Project引发的异常类,消息为“””
,其中
EPackageError.message
是这种格式:
“无法加载包。”
,其中
LoadLibrary()
报告的错误代码的文本-错误193(
ERROR\u BAD\u EXE\u FORMAT
)。此处不接受非现场代码。请在此处以问题本身的形式提供。@KenWhite我做了更改。问题中的错误是error\u BAD\u EXE\u FORMAT,通常在32位进程尝试加载64位DLL或64位进程尝试加载32位DLL时发生。您的库是否依赖于其他不能用于64位的库?可能在编译为BPL时动态链接到该库,而在编译为DLL时静态链接到该库?在不知道实际设置的情况下回答您的问题是否很困难。@RemyLebeau您在哪里看到此错误:错误\u错误\u EXE\u格式?“您在哪里看到此错误:error\U BAD\U EXE\U FORMAT”-这是文本消息
“%1不是有效的Win32应用程序”
。调试器将以这种格式向您显示一条弹出消息:
“Project引发的异常类,其中包含消息“””
,其中
EPackageError。消息
采用这种格式:
”无法加载程序包。“
,其中
LoadLibrary()
报告的错误代码的文本-错误193(
error\u BAD\u EXE FORMAT
)。此处不接受非现场代码。请在问题本身的此处以a的形式提供。@KenWhite我做了更改
unit Unit1;

interface

function MyFunction(const intA, intB: Integer): Integer; stdcall;

implementation

function MyFunction(const intA, intB: Integer): Integer;
begin
   Result := intA + intB;
end;

exports
   MyFunction;

end.