我写了一个动态连接库,里面只有一个函数,现在我想在一个程序中调用他,我在
implentcation 中加入了 function Instr(SourceStr : PChar;Check : Char): Integer; far;
external 'D:\public\程序\Myth.dll';
可是不行,提示,找不到接口什么的??这是怎么回事呀??
哪位大侠能够告诉我动态库到底怎么用呀??多谢???
implentcation 中加入了 function Instr(SourceStr : PChar;Check : Char): Integer; far;
external 'D:\public\程序\Myth.dll';
可是不行,提示,找不到接口什么的??这是怎么回事呀??
哪位大侠能够告诉我动态库到底怎么用呀??多谢???
//--------------------------------------------------------------------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TShowForm = procedure(AHandle: THandle); stdcall; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
DLLHandle: THandle;
ShowForm: TShowForm;
begin
DLLHandle := LoadLibrary('DLLFile.dll');
try
if DLLHandle = 0 then
raise Exception.Create('Load DLLFile.dll error!');
@ShowForm := GetProcAddress(DLLHandle, 'ShowForm');
if @ShowForm = nil then
Abort;
ShowForm(Application.Handle);
finally
FreeLibrary(DLLHandle);
end;
end;end.
//--------------------------------------------------------------------------DLL 工程单元
//--------------------------------------------------------------------------
library DLLFile;{ 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,
Unit1 in 'Unit1.pas' {DllForm};{$R *.RES}exports
ShowForm;begin
end.
//--------------------------------------------------------------------------
DLL Form单元
//--------------------------------------------------------------------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TDllForm = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;procedure ShowForm(AHandle: THandle); stdcall;implementation{$R *.DFM}procedure ShowForm(AHandle: THandle); stdcall;
var
DLLForm: TDllForm;
begin
Application.Handle := AHandle;
DLLForm := TDLLForm.Create(Application);
try
DLLForm.ShowModal;
finally
DLLForm.Free;
end;
end;end.
//
SysUtils,
Classes,
DMTEST in 'DMTEST.pas' {CustomerData: TDataModule},
testunit in 'testunit.pas' {Form2};exports
showzydlr;
{$R *.RES}begin
end.
-------------------------------------------------------
DLL窗体
unit testunit;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids;type
TForm2 = class(TForm)
DBGrid1: TDBGrid;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
procedure showzydlr;stdcall;implementation
uses DMtest;procedure showzydlr;
begin
CustomerData:=TCustomerData.Create(application);
Form2:=TForm2.Create(application);
CustomerData.Orders.Active:=false;
CustomerData.Orders.Active:=true;
Form2.ShowModal;
CustomerData.Free;
Form2.Free;
end;
{$R *.DFM}end.调用
unit zydtest;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button4: TButton;
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationprocedure showzydlr;stdcall;external 'testdll.dll'
{$R *.DFM}procedure TForm1.Button4Click(Sender: TObject);
begin
showzydlr;
end;end.