动态连接库工程的内容如下:
library Project2;{ 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;function To10(a1 : Integer) : word;stdcall;
begin
a1 := a1 * 10 + 4;
result := a1;
end;
{$R *.res}
exports
to10;
begin
end.
调用DLL的EXE文件内容如下:
program P1;uses
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
//Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;function To10(a1 : Integer) : word;stdcall;
implementation{$R *.dfm}
function to10; external 'Project2.dll' name 'to10';
procedure TForm1.Button1Click(Sender: TObject);
var
str : integer;
begin
str := strtoint(edit1.Text);
edit2.Text := inttostr(to10(str));
end;end.先编译DLL,编译通过,生成project2.dll;
然后 我运行exe文件。其中EXE文件中调用了 dll,问错在哪里?
library Project2;{ 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;function To10(a1 : Integer) : word;stdcall;
begin
a1 := a1 * 10 + 4;
result := a1;
end;
{$R *.res}
exports
to10;
begin
end.
调用DLL的EXE文件内容如下:
program P1;uses
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
//Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;function To10(a1 : Integer) : word;stdcall;
implementation{$R *.dfm}
function to10; external 'Project2.dll' name 'to10';
procedure TForm1.Button1Click(Sender: TObject);
var
str : integer;
begin
str := strtoint(edit1.Text);
edit2.Text := inttostr(to10(str));
end;end.先编译DLL,编译通过,生成project2.dll;
然后 我运行exe文件。其中EXE文件中调用了 dll,问错在哪里?
解决方案 »
- 控件没有OnMouseWheel和OnMouseWheelUp,OnMouseWheelDown事件
- 关于Delphi对Vcl和自定义组件的跟踪!郁闷中.....
- 如何制作按住Alt键的同时键入按键s,h,e,n,g的响应事件?
- 如何列出'c:\windows\history\'目录下的所有文件夹及其下的所有文件
- 求救一个delphi的相对路径的函数,比如vb中的app.path之类的
- c/s模式下的服务器中的ADOCONnecting调用问题
- 我只要求有Edit1.text中输入数字,如果输入的有字符则自动去掉,怎么做?
- ord的问题
- 关于消息捕捉(WM_SIZE)
- 在Dbgrid的单元格中设置下拉框的问题!
- 程序启动很慢的问题
- fastreport是否需要注册
Application.CreateForm(TForm1, Form1);
这一行。真是怪了。