如何用DELPHI调用并取得VC中的VOID等类型的函数返回值??? (100分)

I

iseeks1

Unregistered / Unconfirmed
GUEST, unregistred user!
现用delphi调用vc编写的一个动态连接库中的函数,函数接口说明如下:
语法:int SEH_InitialSession(HSE *hSE, unsigned short a,char *b,char *c,unsigned long d,unsigned short e,char *f,char *g )
参数说明:
参数名 含义 输入/输出 参数选项
hSE 函数句柄#define void* HSE Out
a 设备类型 In 2为文件
... ... ... ...
请问如何给出相应的delphi类型?然后对于输出的*hSE如何获取?我的程序如下(???处为疑惑点):
unit normal_in1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
//??????下一句将VC动态链接库内的函数转为delphi声明
function SEH_InitialSession(out hSE: Pointer;a: Integer;const b: WideString;
const c: WideString;
d: Integer;
e: Integer;
const f: WideString;
const g: WideString):Integer;StdCall;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
protected
//??????
myhSE:pointer;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
//??????下一句是调用dll说明
function SEH_InitialSession;external 'SafeEngine.dll' name 'SEH_InitialSession';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
//??????下一句中的myhSE可否直接这样作为参数,然后怎样获取这个输出值
label2.Caption:=inttostr(SEH_InitialSession(myhSE,2,'C:/userkey.key','lala',1000,2,'C:/CertChain.spc',''));
end;

end.
 
你怎么发了两次?
既然是指针,应该不用怎样,函数直接会改输入的参数吧?(乱猜的)
 
不好意思看错题目了。
 
可是我按照这样写的运行程序,会报"access violation at 0×0044ed87:write of address 0×0025ebb3'.的错误
 
????
按照你在题目中写的#define void* HSE,
这里写的对吗???
 
你指的是哪里呀?
语法是:int SEH_InitialSession(HSE *hSE, unsigned short a,char *b,char *c,unsigned long d,unsigned short e,char *f,char *g )
表明是返回一个int类型的函数,对吧?
然后参数说明中指出第一个参数名字为hSE,类型是void*,是输出的,对吧?
 
>>参数名 含义 输入/输出 参数选项
>>hSE 函数句柄#define void* HSE Out
“函数句柄#define void* HSE”是什么意思??说明书上是这么写的吗?
这个意思是说,将程序中所有的“void*”都替换成HSE,那么
在函数SEH_InitialSession(HSE *hSE, unsigned ....中
~~~
的波浪线部分有谁来替换呢?
所以,我觉得有点不对啊?
 
函数句柄#define void* HSE,不是和#define 3.1416 CIR类似嘛?在程序中用a=10*CIR就相当于a=10*3.1416呀
而对于我的情况,就是用void*替换HSE呀
 
iseeks1:
>>函数句柄#define void* HSE,不是和#define 3.1416 CIR类似嘛?在程序中用a=10*CIR就相当于a=10*3.1416呀
>>而对于我的情况,就是用void*替换HSE呀
啊?????老大,这可是C++语言的基本概念啊!!
C++语言中的宏替换应该是这样的,
#define PI 3.1415926
然后在程序中凡是遇到PI,都替换成3.1415926
你正好弄反了[:D][:D]
所以,我觉得有点不对劲呢
 
不好意思哦,我这些天在做别的开发
我今天又试了一下,倒是不报错了,但是lable3.caption取出的东西不和我实际的证书内容一致,象乱码一样的。
是不是还是类型的原因呀?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
function SEH_InitialSession(out hSE: Pointer;PriKeyDevType: Integer;
const strPrivKeyDevParam: Pchar;
const strPriKeyPass: Pchar;
lPriKeyTimeout: Integer;
CertChainDevType: Integer;
const strCertChainDevParam: Pchar;
const strCertChainPass: Pchar):Integer;Cdecl;
function SEH_GetSelfCertificate(hSE: Pointer;devicetype: Integer;deviceparameter: Pchar;password: Pchar;certificate: Pchar;certificatelength: plongint):Integer;Cdecl;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
myhSE:pointer;
cert:array [0..2047] of Char;
certlen:longint;
end;

var
Form1: TForm1;
implementation
function SEH_InitialSession;external 'SafeEngine.dll' name 'SEH_InitialSession';
function SEH_GetSelfCertificate;external 'SafeEngine.dll' name 'SEH_GetSelfCertificate';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
certlen:=2048;
label1.caption:=inttostr(SEH_InitialSession(myhSE,2,'c:/userkey.key','sheca',1000,2,'c:/certchain.spc',''));
label2.caption:=inttostr(SEH_GetSelfCertificate(myhSE,2, 'c:/usercert.der', '',cert,@certlen));
label3.caption:=cert;
end;
end.
 
我又试了试,考虑了尝试Base64Encode,取出的证书倒是很真的证书象了,不是乱码了,可是只取出了一小部分,
比如真证书是MIIEPjCCA6egAwIBAgIEAQHnHjANBgkqhkiG9w0BAQQFDFSDDSFJDSKLNKCLNV'SDJFEINSAIFNFNEISN,我取出的只有
MIIEPjCCA6egAwIBAgIEAQHnHjANBgkqhkiG9w0BAQQF,呜呜,怎么回事呀?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,IdCoder3To4;
function SEH_InitialSession(out hSE: Pointer;PriKeyDevType: Integer;
const strPrivKeyDevParam: Pchar;
const strPriKeyPass: Pchar;
lPriKeyTimeout: Integer;
CertChainDevType: Integer;
const strCertChainDevParam: Pchar;
const strCertChainPass: Pchar):Integer;Cdecl;
function SEH_GetSelfCertificate(hSE: Pointer;devicetype: Integer;deviceparameter: Pchar;password: Pchar;certificate: Pchar;certificatelength: plongint):Integer;Cdecl;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
myhSE:pointer;
cert,envelope:array [0..2047] of Char;
certlen:longint;
end;

var
Form1: TForm1;
implementation
function SEH_InitialSession;external 'SafeEngine.dll' name 'SEH_InitialSession';
function SEH_GetSelfCertificate;external 'SafeEngine.dll' name 'SEH_GetSelfCertificate';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
certlen:=2048;
label1.caption:=inttostr(SEH_InitialSession(myhSE,2,'c:/userkey.key','sheca',1000,2,'c:/certchain.spc',''));
label2.caption:=inttostr(SEH_GetSelfCertificate(@myhSE,2, 'c:/usercert.der', '',cert,@certlen));
label3.caption:=Base64Encode(cert);
end;
end.
 
label显示不全的缘故吧。太短了。:)
 
顶部