Delphi 64bit DLL:OleCtrls事件问题

时间:2017-01-27 10:26:08

标签: delphi 64-bit delphi-10-seattle twebbrowser

我已将DLL从32位转换为64位没有问题,但是当我从占用大量内存的64位应用程序加载此DLL时,应用程序在加载DLL时崩溃并自行关闭。

DLL是一个简单的表单,上面有一个TWebBrowser。我使用Delphi 10 Seattle。

调试后,我发现vcl单元“Vcl.OleCtrls.pas”中的64位转换问题以这种方式解决了:

procedure TOleControl.HookControlWndProc;
var
  WndHandle: HWnd;
begin
  if (FOleInPlaceObject <> nil) and (WindowHandle = 0) then
  begin
    WndHandle := 0;
    FOleInPlaceObject.GetWindow(WndHandle);
    if WndHandle = 0 then raise EOleError.CreateRes(@SNoWindowHandle);
    WindowHandle := WndHandle;
    //DefWndProc := Pointer(GetWindowLong(WindowHandle, GWL_WNDPROC));//OLD
    DefWndProc := Pointer(GetWindowLongPtr(WindowHandle, GWL_WNDPROC));
    CreationControl := Self;
    //SetWindowLong(WindowHandle, GWL_WNDPROC, Longint(@InitWndProc));//OLD
    SetWindowLongPtr(WindowHandle, GWL_WNDPROC, LONG_PTR(@InitWndProc));
    SendMessage(WindowHandle, WM_NULL, 0, 0);
  end;
end;

这解决了崩溃问题,但TWebBrowser事件不再被触发,仅在64位上发生。

如何修复TWebBrowser事件?

您是否发现类似问题或工作方法来修复事件?

由于

1 个答案:

答案 0 :(得分:0)

我发现了另一个生成TWebBrowser事件问题的强制转换错误。 在Emba unit&#34; Vcl.OleCtrls.pas&#34;:

procedure TOleControl.InvokeEvent(DispID: TDispID; var Params: TDispParams);
{$IFDEF CPUX64}
var
  EventMethod: TMethod;
  ParamBlock : TParamBlock;
  i : Integer;
  StackParams2 : array of Int64;

begin
  GetEventMethod(DispID, EventMethod);
  //if Integer(EventMethod.Code) < $10000 then Exit; //OLD
  if Int64(EventMethod.Code) < $10000 then Exit;     //NEW

  ParamBlock.RegRCX := Int64(EventMethod.Data);
  ParamBlock.RegRDX := Int64(Self);

  if Params.cArgs > 2 then
  begin
    SetLength(StackParams2, Params.cArgs-2);
  end;

  for i := 1 to Params.cArgs do
    case i of
      1: ParamBlock.RegR8  := Int64(Params.rgvarg[Params.cArgs-1].unkVal);
      2: ParamBlock.RegR9  := Int64(Params.rgvarg[Params.cArgs-2].unkVal);
    else
      StackParams2[i-3] := Int64(Params.rgvarg[Params.cArgs-i].unkVal);
    end;

  ParamBlock.StackDataSize := Length(StackParams2) * sizeof(Pointer);
  ParamBlock.StackData := @StackParams2[0];

  RawInvoke(EventMethod.Code, @ParamBlock);
end;
{$ELSE !CPUX64}

整数强制转换在高内存使用情况下生成溢出,并且InvokeEvent过程退出而不调用实际事件。解决了Int64演员。

我希望Emba能整合这个修复程序并找到相似的内容。