+ -
当前位置:首页 → 问答吧 → delphi7 调用VB编写的dll的参数传递问题

delphi7 调用VB编写的dll的参数传递问题

时间:2011-11-24

来源:互联网

VB编写的动态库的函数定义:
  '说明: 开始操作
  '参数: i:设备号。0表示第一个设备。
  ' snr:返回4字节的16进制序列号。
  '返回: 调用成功应当返回0;否则返回一个负整数。
  '----------
Declare Function test Lib "Dxq.DLL" (ByVal i As Long, ByRef Snr As String) As Long

在delphi7中调用这个动态库函数,,参数如何定义?主要是Snr的定义问题。
我试过用了pchar、pstring都是返回乱码,后来用了pbyte,可以看到返回数字,但是每次点击运行,这个数字都不一样。(因为是读取设备序列号,应该每次都是一样的)。请高人指导一下。

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

Function test(i:integer; pb:pbyte ) : integer;stdcall;far external Dxq.dll;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var  
  kcr:integer;
  abc:string;
  snr: array[0..3] of byte;
begin

 fillchar(snr,sizeof(snr),#0); 
 kcr:=test(0, @snr) ;
  If kcr <> 0 Then
  showmessage('对不起,执行错误!' );
abc:=inttostr(snr[0])+'-'+inttostr(snr[1])+'-'+inttostr(snr[2])+'-'+inttostr(snr[3]);
edit2.Text:= abc;//每次执行的结果都不一样,如16214340
---------------------------------------------- 

作者: ansuncai   发布时间: 2011-11-24

Function test(const i:integer; var pb:pbyte ) : integer;stdcall;external 'Dxq.dll';
这样?没用过VB十年了。

作者: foxyy8888   发布时间: 2011-11-24

你不能用Stdcall了。应该用 cedel

作者: wonfon   发布时间: 2011-11-24

热门下载

更多