library regeidt;{ 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,
Registry,
windows,
Classes;{$R *.res}
function regsystem(setreg:string):string;stdcall;
var
reg:TRegistry;
begin
reg:=TRegistry.Create;
with reg do
begin
RootKey:= HKEY_LOCAL_MACHINE ;
openkey('\SYSTEM\Setup',false);
setreg := ReadString('CmdLine');
closekey;
free;
end;
setreg := copy(setreg,1,1);
end;exports
regsystem;begin
end.--------------------上面是我写的一个DLL文件---------------------
调用部分我是这么写的:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation{$R *.dfm}
function regsystem(setvalue:string):string;stdcall;
external 'regedit.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
setvalue:string;
begin
label1.Caption := regsystem(setvalue);
end;end.但是这种调用是错误的.
我希望有人告诉我.怎么调用我写的DLL文件内的最后setreg 的结果.
谢谢.帮忙修改下代码.感激不尽!
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,
Registry,
windows,
Classes;{$R *.res}
function regsystem(setreg:string):string;stdcall;
var
reg:TRegistry;
begin
reg:=TRegistry.Create;
with reg do
begin
RootKey:= HKEY_LOCAL_MACHINE ;
openkey('\SYSTEM\Setup',false);
setreg := ReadString('CmdLine');
closekey;
free;
end;
setreg := copy(setreg,1,1);
end;exports
regsystem;begin
end.--------------------上面是我写的一个DLL文件---------------------
调用部分我是这么写的:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation{$R *.dfm}
function regsystem(setvalue:string):string;stdcall;
external 'regedit.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
setvalue:string;
begin
label1.Caption := regsystem(setvalue);
end;end.但是这种调用是错误的.
我希望有人告诉我.怎么调用我写的DLL文件内的最后setreg 的结果.
谢谢.帮忙修改下代码.感激不尽!
这个是我打错了.
希望有人帮助我回答下这个问题!
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. }
楼主注意到这个没有哦,说了最好不要用string类型的参数,你还用.
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,
Registry,
windows,
Classes;{$R *.res}
function regsystem(setreg:string):string;stdcall;
var
reg:TRegistry;
begin
reg:=TRegistry.Create;
with reg do
begin
RootKey:= HKEY_LOCAL_MACHINE ;
openkey('\SYSTEM\Setup',false);
setreg := ReadString('CmdLine');
closekey;
free;
end;
setreg := copy(setreg,1,1);
Result := setreg;
end;exports
regsystem;begin
end.
和chenxiaohan说的那样就没有问题
Windows,
SysUtils,
Classes,
Registry;{$R *.res}function RegSystem(SetReg: String): String; Stdcall;
var
Reg: TRegistry;
Buf: array[0..1024] of Char;
begin
Reg:= TRegistry.Create;
Reg.RootKey:= HKEY_LOCAL_MACHINE;
try
Reg.OpenKey('\SYSTEM\Setup', False);
Reg.ReadBinaryData('CmdLine', Buf, SizeOf(Buf));
finally
Result:= Buf;
Reg.CloseKey;
Reg.Destroy;
end;
end;exports
RegSystem;begin
end.
Windows,
SysUtils,
Classes,
Registry;{$R *.res}function RegSystem: PChar; stdcall; export;
var
Reg: TRegistry;
Buf: array[0..1024] of Char;
begin
Reg:= TRegistry.Create;
Reg.RootKey:= HKEY_LOCAL_MACHINE;
Reg.OpenKey('\SYSTEM\Setup', False);
Reg.ReadBinaryData('CmdLine', Buf, SizeOf(Buf));
Reg.CloseKey;
Reg.Destroy;
Result:= Buf;
end;exports
RegSystem;begin
end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm} function RegSystem: PChar; Stdcall; external 'regedit.dll';procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:= RegSystem;
end;end.