5,392
社区成员
发帖
与我相关
我的任务
分享
library KeyBoradHook;
{ 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
ShareMem,{-----------------------这里}
SysUtils,
Classes,
Unitdll in 'Unitdll.pas';
{$R *.res}
exports
GetConString;
begin
end.
unit Unitdll;
interface
function GetConString(DatePath,OptionPath:String):String;stdcall;
implementation
function GetConString(DatePath,OptionPath:String):String;stdcall;
var ConString:String;
begin
Result:='';
ConString:='aaaaaa'+
DatePath+'bbbbbb'+
OptionPath+'cccccc';
Result:=ConString;
end;
end.
program psst;
uses
ShareMem,{-------------------------这里}
Forms,
Umain in 'Umain.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
unit Umain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
function GetConString(DatePath,OptionPath:String):String; stdcall; external 'KeyBoradHook.dll';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text:=GetConString('d:\ddd','E:www');
end;
end.
library KeyBoradHook;
{ 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,
Unitdll in 'Unitdll.pas';
{$R *.res}
exports
GetConString;
begin
end.
unit Unitdll;
interface
{用了ShortString型}
function GetConString(DatePath,OptionPath:ShortString):ShortString;stdcall;
implementation
function GetConString(DatePath,OptionPath:ShortString):ShortString;stdcall;
var ConString:ShortString;
begin
Result:='';
ConString:='aaaaaa'+
DatePath+'bbbbbb'+
OptionPath+'cccccc';
Result:=ConString;
end;
end.
implementation
function GetConString(DatePath,OptionPath:ShortString):ShortString; stdcall; external 'KeyBoradHook.dll';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text:=GetConString('d:\ddd','E:www');
end;
end.
uses
ShareMem,{----------在最前面}
SysUtils,
Classes;
{另不只是一处引用,工程文件也要做相应的引用}