| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2508 人关注过本帖
标题:delphi 调用c dll传递参数问题
只看楼主 加入收藏
tom0755
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2020-6-4
收藏
 问题点数:0 回复次数:1 
delphi 调用c dll传递参数问题
功能要求,调用用c编写的dll
1、调用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.  


搜索更多相关主题的帖子: the context dll procedure Sender 
2020-06-04 18:30
supermay
Rank: 1
等 级:新手上路
威 望:1
帖 子:34
专家分:0
注 册:2004-10-3
收藏
得分:0 
function worm_user_deriveInitialCredentials(context:PWormContext;
seed:PByte;
seedLength:integer;
initialAdminPuk:PByte;
initialAdminPukLength:integer;
initialAdminPin:PByte;
initialAdminPinLength:integer;
initialTimeAdminPin:PByte;
initialTimeAdminPinLength:integer):WormError; cdecl; external 'WormAPI.dll';

你看看函数的定义
 unsigned char是指byte,
int->integer

2021-10-20 09:32
快速回复:delphi 调用c dll传递参数问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041533 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved