X
xewei
Unregistered / Unconfirmed
GUEST, unregistred user!
错误提示:Invalid poniter operation
但是DLL的函数计算出来了,请高手指点。
unit RegSoft;
interface
function GetSerialNumber(var UserName:string):string;stdcall;
function test():string;stdcall;
implementation
uses Sysutils;
const SerialBaseValue = 7756;
function GetSerialNumber(var UserName:string):string;stdcall;
var
i,n:integer;
begin
n := 1;
for i:=1 to length(UserName) do
n := abs((ord(UserName)*n+55555555)) mod 10;
n := n+SerialBaseValue;
Result := copy(inttostr,1,8);
end;
function test():string;stdcall;
begin
test := 'successfull';
end;
end.
library cxw;
{ 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,
RegSoft;
exports
GetSerialNumber,
test;
begin
//SaveExit := ExitProc
// save exit procedure chain
//ExitProc := @LibExit
// install LibExit exit procedure
end.
unit FormSerialCalc;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TSerialCalcForm = class(TForm)
Label1: TLabel;
edUserName: TEdit;
Label2: TLabel;
edSerialNumber: TEdit;
btnBuild: TButton;
btnExit: TButton;
procedure FormClose(Sender: TObject
var Action: TCloseAction);
procedure btnExitClick(Sender: TObject);
procedure btnBuildClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
SerialCalcForm: TSerialCalcForm;
implementation
function GetSerialNumber(var UserName:string):string;stdcall;external 'cxw.dll';
function test():string;stdcall;external 'cxw.dll';
{$R *.DFM}
procedure TSerialCalcForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
action := cafree;
end;
procedure TSerialCalcForm.btnExitClick(Sender: TObject);
begin
close;
end;
procedure TSerialCalcForm.btnBuildClick(Sender: TObject);
var
strUserName:string;
begin
strUserName := trim(edUserName.Text);
try
edSerialNumber.Text := GetSerialNumber(strUserName);
except
end;
end;
end.
但是DLL的函数计算出来了,请高手指点。
unit RegSoft;
interface
function GetSerialNumber(var UserName:string):string;stdcall;
function test():string;stdcall;
implementation
uses Sysutils;
const SerialBaseValue = 7756;
function GetSerialNumber(var UserName:string):string;stdcall;
var
i,n:integer;
begin
n := 1;
for i:=1 to length(UserName) do
n := abs((ord(UserName)*n+55555555)) mod 10;
n := n+SerialBaseValue;
Result := copy(inttostr,1,8);
end;
function test():string;stdcall;
begin
test := 'successfull';
end;
end.
library cxw;
{ 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,
RegSoft;
exports
GetSerialNumber,
test;
begin
//SaveExit := ExitProc
// save exit procedure chain
//ExitProc := @LibExit
// install LibExit exit procedure
end.
unit FormSerialCalc;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TSerialCalcForm = class(TForm)
Label1: TLabel;
edUserName: TEdit;
Label2: TLabel;
edSerialNumber: TEdit;
btnBuild: TButton;
btnExit: TButton;
procedure FormClose(Sender: TObject
var Action: TCloseAction);
procedure btnExitClick(Sender: TObject);
procedure btnBuildClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
SerialCalcForm: TSerialCalcForm;
implementation
function GetSerialNumber(var UserName:string):string;stdcall;external 'cxw.dll';
function test():string;stdcall;external 'cxw.dll';
{$R *.DFM}
procedure TSerialCalcForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
action := cafree;
end;
procedure TSerialCalcForm.btnExitClick(Sender: TObject);
begin
close;
end;
procedure TSerialCalcForm.btnBuildClick(Sender: TObject);
var
strUserName:string;
begin
strUserName := trim(edUserName.Text);
try
edSerialNumber.Text := GetSerialNumber(strUserName);
except
end;
end;
end.