delphi调用VB编写的DLL的函数,整数型参数可以,字符串型函数就不行 20
unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function OpenPort(nPort:integer): Integer; stdcall; external 'SYp2p.dll';
function DllVersion(): PChar; stdcall; external 'SYp2p.dll';
function ClosePort(): Integer; stdcall; external 'SYp2p.dll';
function Settime(tva:pchar;var rva:pchar): Integer; stdcall;external 'SYp2p.dll';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
nRecode:Integer;
begin
nRecode:=OpenPort(4);
ShowMessage('OpenPort(4):'+intTostr(nRecode));
closeport();
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage(DllVersion());
end;
procedure TForm1.Button3Click(Sender: TObject);
var
rva:pchar;
nRecode:Integer;
begin
Getmem(rva,1000);
nRecode :=settime(pchar('0.0.0'),rva);
ShowMessage('settime:'+intTostr(nRecode));
end;
end.
说明:点击button1、button2,但点击button3就总是报“找不到程序入口settime于动态库SYp2p上”,有时就报内存访问出错,写内存失败(英文提示)
为什么同一个DLL,传入整形参数或不传入参数就可以,传入STRING参数就不行????
在VB中的定义如下,执行都没有任何问题:
Public Declare Function OpenPort Lib "SYp2p" (ByVal port As Integer) As Integer
Public Declare Function ClosePort Lib "SYp2p" () As Integer
Public Declare Function SetOverTime Lib "SYp2p" (ByVal nOver As Long) As Integer
不好意思,VB声明部分拷错函数了,应该是:
Public Declare Function SetTime Lib "SYp2p" (ByVal tVa As String, ByVal RVA As String) As Integer 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function OpenPort(nPort:integer): Integer; stdcall; external 'SYp2p.dll';
function DllVersion(): PChar; stdcall; external 'SYp2p.dll';
function ClosePort(): Integer; stdcall; external 'SYp2p.dll';
function Settime(tva:pchar;var rva:pchar): Integer; stdcall;external 'SYp2p.dll';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
nRecode:Integer;
begin
nRecode:=OpenPort(4);
ShowMessage('OpenPort(4):'+intTostr(nRecode));
closeport();
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage(DllVersion());
end;
procedure TForm1.Button3Click(Sender: TObject);
var
rva:pchar;
nRecode:Integer;
begin
Getmem(rva,1000);
nRecode :=settime(pchar('0.0.0'),rva);
ShowMessage('settime:'+intTostr(nRecode));
end;
end.
说明:点击button1、button2,但点击button3就总是报“找不到程序入口settime于动态库SYp2p上”,有时就报内存访问出错,写内存失败(英文提示)
为什么同一个DLL,传入整形参数或不传入参数就可以,传入STRING参数就不行????
在VB中的定义如下,执行都没有任何问题:
Public Declare Function OpenPort Lib "SYp2p" (ByVal port As Integer) As Integer
Public Declare Function ClosePort Lib "SYp2p" () As Integer
Public Declare Function SetOverTime Lib "SYp2p" (ByVal nOver As Long) As Integer
不好意思,VB声明部分拷错函数了,应该是:
Public Declare Function SetTime Lib "SYp2p" (ByVal tVa As String, ByVal RVA As String) As Integer 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询