0

Good day, I write plugins dll from the main form call the dll

type
  TCreateCustomWindow=function(ParentFrame:TWinControl; ParentHandle:integer; ParentRect:TRect; var WinHandle:THandle):integer; stdcall;

var
CreateW:TCreateCustomWindow;
begin
CreateW:=GetProcAddress(FHLib,'Create_LEF');
if Assigned(CreateW) then
begin
  if Assigned(CreateW) then LEFT_OKNO:=CreateW(ScrollBox2, ScrollBox2.Handle, ClientRect, FChildHandle);
end;

in the dll itself, it looks like

function Create_LEF(ParentFrame:TWinControl; ParentHandle:integer; ParentRect:TRect; var WinHandle:THandle):integer; stdcall; export;
begin
  Result:=0;
  WinHandle:=0;
  try
    FD3:=TForm3.Create(nil);
    FD3.Parent:= ParentFrame;
    Result:=integer(FD3);
    WinHandle:=FD3.Handle;
    if ParentHandle<>0 then begin
      SetParent(WinHandle,ParentHandle);
      with FD3 do begin
      FD3.Align:=alTop;
      FD3.Width:=ParentFrame.Width;
      hirina_left:=ParentFrame.Width;
      FD3.Show;
      end;
    end;
  except
    On E:exception do MessageDlg(E.Message,mtError,[mbOK],0);
  end;
end;

the problem is that I can not edit cells cxGrid can I do something wrong?

fedormoore
  • 15
  • 1
  • 8
  • In your code there is no mention about a cxGrid (DevExpress grid?) so it is hard to tell. Can you post some relevant code and some steps that you already tried? – Birger Mar 06 '12 at 06:31
  • You cannot safely pass Delphi objects across DLL boundaries. That TWinControl parameter is no good. Why do you need to pass it as well as its HWND? Not sure that's relevant to the problem though. – David Heffernan Mar 06 '12 at 06:31
  • in the main program I have a component which ScrollBox and must place the file from the dll form, when you press the button "СКРЫТЬ" days of the forms should decrease in the amount of in the other catch up upstairs, with the code I provided above, it works, but you can not edit cxGrid Here is the link to the screenshot http://s51.radikal.ru/i132/1203/da/3787a490fd8f.jpg – fedormoore Mar 06 '12 at 11:49

1 Answers1

0

I have encountered this before, and there are a couple of ways around it. It was a long time ago, so you will have to do a bit of trial and error.

function Create_LEF(ParentFrame:TWinControl; ParentHandle:integer; ParentRect:TRect; var WinHandle:THandle):integer; stdcall; export;
begin
  Result:=0;
  WinHandle:=0;
  try
    FD3:=TForm3.Create(nil);
    FD3.Parent:= ParentFrame;
    Result:=integer(FD3);
    WinHandle:=FD3.Handle;
    if ParentHandle<>0 then begin
      with FD3 do begin
        ParentWindow := ParentFrame.Handle;
        Parent := ParentFrame;
        Align:=alTop;
        Width:=ParentFrame.Width;
        hirina_left:=ParentFrame.Width;
        Show;
      end;
    end;
  except
    On E:exception do MessageDlg(E.Message,mtError,[mbOK],0);
  end;
end;

That should fix your problem. Failing that, try setting DLL's Application.Handle to the application's Application.Handle. I usually do this with an Init function in the DLL. This function stores the the DLL's Application.Handle in a global variable and reassigns it to the application's handle, passed as a parameter to the function. When you unload the DLL, you assign the DLL's application.handle back to its original value, otherwise everything goes South.

var
    FOldHandle: THandle;

procedure Init(AHandle: THandle); stdcall;
begin
    FOldHandle := Application.Handle;
    Application.Handle := AHandle;
end;

procedure UnInit; stdcall;
begin
    Application.Handle := FOldHandle;
end;
...
Peter
  • 1,055
  • 6
  • 8