delphi 调用c dll传递参数问题
功能要求,调用用c编写的dll1、调用worm_cleanup,进行初始化,这个调用成功了、
2、调用worm_user_deriveInitialCredentials,报错“无效参数”
请高手们看看,参数哪儿不对?
感谢,感谢!
delphi代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
WormContext = integer;
PWormContext = ^WormContext;
WormError = word;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ptsecontext: PWormContext;
pin1,pin2,puk1,puk2,timepin1,timepin2:PAnsiChar;
pinlen1,pinlen2,puklen1,puklen2,timepinlen1,timepinlen2:UInt64;
err_str : WormError; //WormError;
user_id:integer;
implementation
{$R *.dfm}
function worm_getVersion : PAnsiChar; stdcall; external 'WormAPI.dll';
function worm_signatureAlgorithm : PAnsiChar; stdcall; external 'WormAPI.dll';
function worm_logTimeFormat : PAnsiChar; stdcall; external 'WormAPI.dll';
function worm_init(context:PWormContext; mountPoint: PAnsiChar): WormError; cdecl; external 'WormAPI.dll';
function worm_cleanup(context:WormContext): WormError; cdecl; external 'WormAPI.dll';
function worm_user_deriveInitialCredentials(context:WormContext;seed:PByte;seedLength:UInt64;initialAdminPuk:PAnsiChar;initialAdminPukLength:UInt64;initialAdminPin:PAnsiChar;initialAdminPinLength:UInt64;initialTimeAdminPin:PAnsiChar;initialTimeAdminPinLength:UInt64):WormError; cdecl; external 'WormAPI.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage('Version:'+StrPas(worm_getVersion()));
showmessage('signatureAlgorithm:'+StrPas(worm_signatureAlgorithm()));
showmessage('worm_logTimeFormat:'+StrPas(worm_logTimeFormat()));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
getmem(ptsecontext,2000);
err_str := worm_init(ptsecontext,PAnsiChar('D:'));
if err_str=0 then
showmessage('ok')
else
showmessage('err');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
err_str := worm_cleanup(ptsecontext^);
if err_str=0 then
showmessage('ok')
else
showmessage('err');
end;
procedure TForm1.Button4Click(Sender: TObject);
var
tseseed:pbyte;
ps:Pchar;
begin
puklen1:=6;
pinlen1:=5;
timepinlen1:=5;
ps:=pchar('SwissbitSwissbit');
getmem(tseseed,16);
move(ps^,tseseed^,16);
err_str:=worm_user_deriveInitialCredentials(ptsecontext^,tseseed,16,puk1,puklen1,pin1,pinlen1,timepin1,timepinlen1);
showmessage(inttostr(err_str));
if err_str=0 then
showmessage('okok')
else
showmessage('err');
showmessage(pin1);
end;
end.
==================================================================
c写的api函数如下
WORMAPI WormError WORMAPI_CALL worm_init ( WormContext ** context,
const char * mountPoint
)
Initializes the library by setting up a new context.
This method will validate if there is a valid Swissbit TSE at the given mount point and will fail if there is none.
A call to this method must be paired with a call to worm_cleanup in order to release all resources belonging to this context after the TSE is not in use anymore.
Parameters
[out] context A fully initialized WormContext
[in] mountPoint Location of the Swissbit TSE. On Windows, this is the drive letter followed by a colon (e.g. 'e:'). On Linux, this is the directory where the TSE is mounted without a trailing slash (e.g. '/mnt/media/swissbit').
-----------------------------------------------------------------------------------
WORMAPI WormError WORMAPI_CALL worm_user_deriveInitialCredentials ( WormContext * context,
const unsigned char * seed,
int seedLength,
unsigned char * initialAdminPuk,
int initialAdminPukLength,
unsigned char * initialAdminPin,
int initialAdminPinLength,
unsigned char * initialTimeAdminPin,
int initialTimeAdminPinLength
)
Derives the initial credentials needed to set up the TSE.
The initial credentials will only consist of ASCII digits between '0' and '9' and will be random for each individual TSE.
Parameters
[in] context Library context
[in] seed Seed used to calculate the credential. This is the secret that is used to derive the initial credentials during TSE production. For Swissbit samples, this is "SwissbitSwissbit" (without quotes).
[in] seedLength Length of seed. Must be at most 32 bytes.
[out] initialAdminPuk Initial Admin PUK. Must be allocated by the caller.
[in] initialAdminPukLength Length of initialAdminPuk. Must be 6.
[out] initialAdminPin Initial Admin PIN. Must be allocated by the caller.
[in] initialAdminPinLength Length of initialAdminPin. Must be 5.
[out] initialTimeAdminPin Initial TimeAdmin PIN. Must be allocated by the caller.
[in] initialTimeAdminPinLength Length of initialTimeAdminPin. Must be 5.