DLL参数传递问题(未使用过DLL的勿进!)(100分)

E

eire

Unregistered / Unconfirmed
GUEST, unregistred user!
DLL中不能使用VARIANT类型作为参数传递?

---------------------------
Debugger Exception Notification
---------------------------
Project Project3.exe raised exception class EVariantBadVarTypeError with message 'Invalid variant type'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
//调用
function test(params:variant):boolean;external 'Project2.dll' name 'test';

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
var
A:Variant;
begin
A := VarArrayCreate([0, 1], varVariant);
A[0] := '202.96.31.29';
test(a);
end;
end.

//DLL部分.
library Project2;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
Unit2 in 'dll/Unit2.pas';

{$R *.res}

exports
test;

begin

end.


// Unit2
function test(params:variant):boolean;stdcall;

implementation

function test(params:variant):boolean;
begin
showmessage(params[0]);
end;

 
在 uses 中添加 Sharemem 单元。
程序发布的时候要把borlndmm.dll带上。
 
是不是这样解决,下班了,没试验
uses
ShareMem,
SysUtils,
Classes,
Unit2 in 'dll/Unit2.pas';

{$R *.res}
function test(params:variant):boolean;stdcall;
begin
showmessage(params[0]);
end;
exports
test;

begin

end.
 
function test(params:variant):boolean;external 'Project2.dll' name 'test';
改为下面的:
function test(params:variant):boolean;stdcall;external 'Project2.dll' name 'test';
这样就OK了!
 
同意 stdcall
 
library Project2;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
Unit2 in 'Unit2.pas';
{$R *.res}
exports
test;
begin
end.

unit Unit2;

interface
function test(params:variant):boolean;stdcall;


implementation
uses dialogs;
function test(params:variant):boolean;stdcall;
begin
showmessage(params[0]);
end;
end.


function test(params:variant):boolean;stdcall;
external 'Project2.dll' name 'test';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
A:Variant;
begin
A := VarArrayCreate([0, 1], varVariant);
A[0] := '202.96.31.29';
test(a);
end;
测试通过,输出202.96.31.29


 
声明的时候不要忘了加stdcall,改成这样测试就OK了:
function test(params: variant):boolean;stdcall;
external 'Project2.dll' name 'test'
 
测试通过.谢谢各位.
分不多.请谅.
 
搞错没有!!!!!!!!!!11
 
顶部