delphi动态调用dll窗体

public...end.后的声明 写道
TShowForm=Function (AHandle:THandle;ACaption:Pchar):Boolean;Stdcall;
 
调用部分代码 写道
procedure TForm1.N5Click(Sender: TObject);
   var mainfrm,DllForm:THandle;
         ShowForm:TShowForm;
begin
     mainfrm:=Form1.Handle;
     DllForm:=LoadLibrary('JSJ.dll');
    Try
    begin
        if DllForm<>0 then 
        begin
           @ShowForm:=GetProcAddress(DllForm,'ShowForm');
           ShowForm(mainfrm,'进售价');
        end
        else
        begin
            RaiseLastWin32Error;
        end;
   end;
   Finally
       FreeLibrary(DllForm);
   end;
end;

 

dll动态链接库代码 写道
Function ShowForm(AHandle:THandle;ACaption:Pchar):Boolean;StdCall;
     var AForm:TForm1;
begin
     Result:=False;
     Application.Handle:=AHandle;
     AForm:=TForm1.Create(Application);
     Try
         Aform.Caption:=ACaption;
         AForm.ShowModal;
         Result:=True;
     Finally
         AForm.Free;
    end;
end;
Exports
     ShowForm;
begin
end.

 

你可能感兴趣的:(Delphi)