S
softdelphi8
Unregistered / Unconfirmed
GUEST, unregistred user!
现在把代码全部列出来,请大家帮助解决出现错误的地方
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
Type
TForm1 = Class(TForm)
Button1: TButton;
Panel1: TPanel;
Procedure Button1Click(Sender: TObject);
Private
{ Private declarations }
Public
{ Public declarations }
End;
Type
TCreateControl = Function(AppHandle: THandle; AOwner: TComponent;
PControl: TWinControl): TEdit; stdcall;
EDLLLoadError = Class(Exception);
Var
Form1: TForm1;
Implementation
{$R *.dfm}
Procedure TForm1.Button1Click(Sender: TObject);
Var
LibHandle: THandle;
CreateControl: TCreateControl;
Begin
LibHandle := LoadLibrary('DLLPro.dll');
Try
If LibHandle = HINSTANCE_ERROR Then
Raise EDLLLoadError.Create('Unable to Load DLL');
@CreateControl := GetProcAddress(LibHandle, 'CreateControl');
If Not (@CreateControl = Nil) Then
[red]CreateControl(Application.Handle, Nil, Panel1);[/red] // 调用DLL后出错
Finally
FreeLibrary(LibHandle);
End;
End;
End.
上面的代码是EXE主程序调用
下面是DLL代码:
Library DLLPro;
Uses
ShareMem,
SysUtils,
StdCtrls,
ExtCtrls,
Controls,
Forms,
Classes;
{$R *.res}
Function CreateControl(AppHandle: THandle; AOwner: TComponent;
PControl: TWinControl): TEdit; Stdcall;
Var
Edit1: TEdit;
Begin
Application.Handle := AppHandle;
Edit1 := TEdit.Create(AOwner);
Edit1.Parent := PControl;
Edit1.Text := 'DLL Create Edit1';
Edit1.Name := 'Edit1';
Edit1.Left := 100;
Edit1.Top := 100;
Result := Edit1;
End;
Exports
CreateControl;
Begin
End.
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
Type
TForm1 = Class(TForm)
Button1: TButton;
Panel1: TPanel;
Procedure Button1Click(Sender: TObject);
Private
{ Private declarations }
Public
{ Public declarations }
End;
Type
TCreateControl = Function(AppHandle: THandle; AOwner: TComponent;
PControl: TWinControl): TEdit; stdcall;
EDLLLoadError = Class(Exception);
Var
Form1: TForm1;
Implementation
{$R *.dfm}
Procedure TForm1.Button1Click(Sender: TObject);
Var
LibHandle: THandle;
CreateControl: TCreateControl;
Begin
LibHandle := LoadLibrary('DLLPro.dll');
Try
If LibHandle = HINSTANCE_ERROR Then
Raise EDLLLoadError.Create('Unable to Load DLL');
@CreateControl := GetProcAddress(LibHandle, 'CreateControl');
If Not (@CreateControl = Nil) Then
[red]CreateControl(Application.Handle, Nil, Panel1);[/red] // 调用DLL后出错
Finally
FreeLibrary(LibHandle);
End;
End;
End.
上面的代码是EXE主程序调用
下面是DLL代码:
Library DLLPro;
Uses
ShareMem,
SysUtils,
StdCtrls,
ExtCtrls,
Controls,
Forms,
Classes;
{$R *.res}
Function CreateControl(AppHandle: THandle; AOwner: TComponent;
PControl: TWinControl): TEdit; Stdcall;
Var
Edit1: TEdit;
Begin
Application.Handle := AppHandle;
Edit1 := TEdit.Create(AOwner);
Edit1.Parent := PControl;
Edit1.Text := 'DLL Create Edit1';
Edit1.Name := 'Edit1';
Edit1.Left := 100;
Edit1.Top := 100;
Result := Edit1;
End;
Exports
CreateControl;
Begin
End.