动态链接库(最基础的问题)(50分)

  • 主题发起人 金风吹雪
  • 开始时间

金风吹雪

Unregistered / Unconfirmed
GUEST, unregistred user!
我要使用动态链接库:
=======================
动态库是这样的:
-----------------------
library Myddl;
{ 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 funS:pChar;
begin
Result:='LibraryOfFile is Myddl.ddl';
end;

exports
funS Name 'NewName';
{$R *.res}
begin
end.
----------------------
使用的程序是这样写的:
----------------------
unit uLibrary;
interface
uses
Windows, Messages, SysUtils, Variants, 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;
implementation
const
grid='MyddL.DDL';
function funS:pChar;stdcall;external grid name 'NewName';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
S:string;
begin
S:=funS;
ShowMessage(S);
end;

end.
----------------------
工程文件:
----------------------
program pLibrary;
uses
Forms,
uLibrary in 'uLibrary.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
----------------------
运行可执行文件,即pLibrary.exe
结果出现了:
“没有找到'MyddL.DDL',因此,这个应用程序未能启动,重新安装应用程序扩展,可能会修复此问题.”
我的动态链接库那里出了问题?
怎样解决这个问题?
怎样做?
谢谢!
=======================
 
晕。。
后缀名应该是 dll 吧?
grid='MyddL.DlL';
//????
 
1、路径是否正确
2、function funS:pChar;
StdCall;
 
将机器重一以下试试!要不然从新建一个DLL!
 
你的dll需要拷贝到pLibrary.exe相同的目录。
 
问题解决了!
=======================
to 来如风
后缀名有问题!
======================
不过,我的问题是没有编译“动态链接库”;
总体程序如下!
======================
{******工程文件******}
program pfrmLibrary;
uses
Forms,
uLibrary in 'uLibrary.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
{******窗体文件******}
unit uLibrary;
interface
uses
Windows, Messages, SysUtils, Variants, 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;
implementation

const
grid='LibraryA.dll';
function funS:pChar;stdcall;external grid name 'NewName';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
S:string;
begin
S:=funS;
ShowMessage(S);
end;

end.
{******动态链接库文件******}
library LibraryA;
{ 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 funS:pChar;
begin
Result:='this is LibraryA';
end;

exports
funS Name 'NewName';
{$R *.res}
begin
end.
================================
 
[?][red]Result:='LibraryOfFile is Myddl.dll';[/red]
const
[?][red] grid='MyddL.dll';[/red]
dll文件要放在调用它的[blue]EXE文件[/blue]同一目录下或[blue]%系统目录%/system32/[/blue]下面
 
有些时候是低级错误!提问题可要当心呀。
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
584
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部