关于动态链接库的一个小问题 ( 积分: 5 )

  • 主题发起人 主题发起人 txl2001
  • 开始时间 开始时间
T

txl2001

Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
我的源代码如下:
library Test;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
u_main in 'u_main.pas' {F_Main};

{$R *.RES}
EXPORTS
start;

begin
end.

主窗体代码:
unit u_main;

interface

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

type
TF_Main = class(TForm)
Button1: TButton;
procedure LockedMouse(Rect: TRect;Bz:Boolean);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure start(Sender:Tobject);stdcall ;
private
{ Private declarations }
public
{ Public declarations }
end;

var
F_Main: TF_Main;

implementation

{$R *.DFM}
procedure TF_Main.start(Sender:Tobject);stdcall ;
begin
application.CreateForm (TF_Main,f_main);

end;

procedure TF_Main.LockedMouse(Rect: TRect;Bz:Boolean);
var
Temp:integer;
Rect1:Trect;
begin
if Bz=true then
begin
rect1.Left:=rect.Left;
Rect1.Top:=rect.Top;
Rect1.Bottom:=rect.Bottom;
Rect1.Right:=rect.Right;
end
else
begin
rect1.Left:=0;
Rect1.Top:=0;
Rect1.Bottom:=screen.DesktopHeight;
Rect1.Right:=Screen.DesktopWidth;
end;
ClipCursor(@rect1);
SystemParametersInfo(spi_screensaverrunning,1,@temp,0);
end;

procedure TF_Main.Button1Click(Sender: TObject);
begin
close;
end;

procedure TF_Main.FormCreate(Sender: TObject);
var
rect:Trect;
begin
rect.Left :=F_Main.Left ;
rect.Right :=F_main.Left +F_main.Width ;
rect.Top:=f_main.Top ;
rect.Bottom :=F_main.Top +F_main.Height ;
lockedmouse(rect,true);
end;

end.


运行的时候提示找不到start ,请各位不吝赐教..
 
代码:
我的源代码如下:
library Test;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
u_main in 'u_main.pas' {F_Main};

{$R *.RES}
EXPORTS
start;

begin
end.

主窗体代码:
unit u_main;

interface

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

type
TF_Main = class(TForm)
Button1: TButton;
procedure LockedMouse(Rect: TRect;Bz:Boolean);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure start(Sender:Tobject);stdcall ;
private
{ Private declarations }
public
{ Public declarations }
end;

var
F_Main: TF_Main;

implementation

{$R *.DFM}
procedure TF_Main.start(Sender:Tobject);stdcall ;
begin
application.CreateForm (TF_Main,f_main);

end;

procedure TF_Main.LockedMouse(Rect: TRect;Bz:Boolean);
var
Temp:integer;
Rect1:Trect;
begin
if Bz=true then
begin
rect1.Left:=rect.Left;
Rect1.Top:=rect.Top;
Rect1.Bottom:=rect.Bottom;
Rect1.Right:=rect.Right;
end
else
begin
rect1.Left:=0;
Rect1.Top:=0;
Rect1.Bottom:=screen.DesktopHeight;
Rect1.Right:=Screen.DesktopWidth;
end;
ClipCursor(@rect1);
SystemParametersInfo(spi_screensaverrunning,1,@temp,0);
end;

procedure TF_Main.Button1Click(Sender: TObject);
begin
close;
end;

procedure TF_Main.FormCreate(Sender: TObject);
var
rect:Trect;
begin
rect.Left :=F_Main.Left ;
rect.Right :=F_main.Left +F_main.Width ;
rect.Top:=f_main.Top ;
rect.Bottom :=F_main.Top +F_main.Height ;
lockedmouse(rect,true);
end;

end.


运行的时候提示找不到start ,请各位不吝赐教..
 
这句不对:
procedure start(Sender:Tobject);stdcall ;
应改为:
procedure start(Sender:Tobject);stdcall;external'DLL名.dll'; //
 
加上external'test.dll' 也不行啊,
我先创建一个dll 然后加上一个窗体. 可是不能运行啊.代码如上.
 
适一下这个吧!
---------------------------------
主窗体代码:
unit u_main;

interface

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

type
TF_Main = class(TForm)
Button1: TButton;
procedure LockedMouse(Rect: TRect;Bz:Boolean);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
F_Main: TF_Main;
procedure start(Sender:Tobject);stdcall ;//修改
implementation

{$R *.DFM}
//修改
procedure start(Sender:Tobject);stdcall ;
begin
application.CreateForm (TF_Main,f_main);

end;

procedure TF_Main.LockedMouse(Rect: TRect;Bz:Boolean);
var
Temp:integer;
Rect1:Trect;
begin
if Bz=true then
begin
rect1.Left:=rect.Left;
Rect1.Top:=rect.Top;
Rect1.Bottom:=rect.Bottom;
Rect1.Right:=rect.Right;
end
else
begin
rect1.Left:=0;
Rect1.Top:=0;
Rect1.Bottom:=screen.DesktopHeight;
Rect1.Right:=Screen.DesktopWidth;
end;
ClipCursor(@rect1);
SystemParametersInfo(spi_screensaverrunning,1,@temp,0);
end;

procedure TF_Main.Button1Click(Sender: TObject);
begin
close;
end;

procedure TF_Main.FormCreate(Sender: TObject);
var
rect:Trect;
begin
rect.Left :=F_Main.Left ;
rect.Right :=F_main.Left +F_main.Width ;
rect.Top:=f_main.Top ;
rect.Bottom :=F_main.Top +F_main.Height ;
lockedmouse(rect,true);
end;

end.
 
type
TF_Main = class(TForm)
Button1: TButton;
procedure LockedMouse(Rect: TRect;Bz:Boolean);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure start(Sender:Tobject);stdcall ;
private
{ Private declarations }
public
{ Public declarations }
end;

var
F_Main: TF_Main;

implementation

{$R *.DFM}
procedure TF_Main.start(Sender:Tobject);stdcall ;
begin
application.CreateForm (TF_Main,f_main);

end;
换成


type
TF_Main = class(TForm)
Button1: TButton;
procedure LockedMouse(Rect: TRect;Bz:Boolean);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
// procedure start(Sender:Tobject);stdcall ;//需要全局过程
private
{ Private declarations }
public
{ Public declarations }
end;

var
F_Main: TF_Main;
procedure start(Sender:Tobject);//全局过程
implementation

{$R *.DFM}
procedure start(Sender:Tobject);//全局过程
begin
application.CreateForm (TF_Main,f_main);

end;
 
把start 改为全局过程后,编译通过了,不过提示我指定一个host application,我的程序里面没有 主程序怎么办啊,,只有 一个lib 和一个lib下面的窗体,,,我怎么添加一个主程序呢,?? 我又怎么把主程序和lib连起来呢??
 
吐血结帖.
 
后退
顶部