动态连接库dll 为什么总是报无效的窗口句柄(50分)

  • 主题发起人 主题发起人 12345yy
  • 开始时间 开始时间
1

12345yy

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是我的代码,请各位大虾指点
library FormDll;

uses
SysUtils,
Classes,
UmyForm in 'UmyForm.pas' {frmdll};

exports
showformdll;

{$R *.RES}
begin
end.

********************************************************
unit UmyForm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
Tfrmdll = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmdll: Tfrmdll;
procedure showformdll(AppHandle: THandle);Stdcall;

implementation

{$R *.DFM}

procedure showformdll(AppHandle: THandle);
begin
Application.Handle := AppHandle;
With Tfrmdll.Create(Application) do
try
ShowModal;
finally
Free;
end;
end;

end.

*******************************************************
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
procedure showformdll; stdcall external 'FormDll.dll';

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
showformdll;
end;

end.

 
在你的调用程序中
procedure showformdll; stdcall external 'FormDll.dll';
在你的DLL中
procedure showformdll(AppHandle: THandle);Stdcall;
这两个申明一样吗?
 
在你的调用过程中,应将
procedure showformdll; stdcall external 'FormDll.dll';
改为
procedure showformdll(AppHandle: THandle); stdcall external 'FormDll.dll';

showformdll;
改为
showformdll(application.Handle);

这样,就可以了,不防试一试
 
接受答案了.
 
后退
顶部