请各位大师帮我检查是否有错误,关于过程类型的问题! ( 积分: 100 )

Y

yxzymh

Unregistered / Unconfirmed
GUEST, unregistred user!
调用C编写的DLL,C中定义如下:
typedef void __stdcall (*fun_AddResult)(char pDataStr[10][255],double pDataDouble[100]);

extern "C&quot
void __declspec(dllimport) __stdcall SetBackColor(TColor pBkColor);

extern "C&quot
void __declspec(dllimport) __stdcall FanSelect(
void *pSNames,
const int pSNameCount,
void *pSubSNames,
const int pSubSNameCount,
const double &pF,
const int &pFUnitType,
const double &pP,
const int &pPUnitType,
fun_AddResult pAddResult//函数指针,用于回传数据
);

看我编写的调用:

unit GlobalVar;

interface
Uses
Dialogs,SysUtils;

type
TCharArray=array [0..9] Of Array [0..254] of Char;
pCharArray=^TCharArray;
TDoubleArray=array [0..99] of Double;
pDoubleArray=^TDoubleArray;
fun_AddResult=Procedure(pDataStr:TCharArray;pDataDouble:TDoubleArray);StdCall;

Var
Result1 : TCharArray;
Result2 : TDoubleArray;

Procedure FanSelect(pSNames : Pchar;pSNameCount : Integer;
pSubSNames : Pchar;pSubSNameCount : Integer;
pF : PDouble;pFUnitType : PInteger;
pP : PDouble;pPUnitType : PInteger

pAddResult : fun_AddResult);StdCall;External 'LMES.dll';

Procedure MyProc(pDataStr:TCharArray;pDataDouble:TDoubleArray);StdCall;
Procedure GetFanSelectInfo();

implementation

Procedure MyProc(pDataStr:TCharArray;pDataDouble:TDoubleArray);StdCall;
Begin
pDataStr := Result1;
pDataDouble := Result2;
End;

Procedure GetFanSelectInfo();
Var
SNames,SubSNameS : Pointer;
ResultS : Fun_AddResult;
Result1 : TCharArray;
Result2 : TDoubleArray;
pF,pP : PDouble;
pFUnitType,pPUnitType : PInteger;
begin
SNames := Pchar('SYT');
SubSNameS := Pchar('L');
New(pF);
New(pFUnitType);
New(pP);
New(pPUnitType);
pF^ := 9837;
pFUnitType^ := 0;
pP^ := 750;
pPUnitType^ := 0

ResultS := MyProc;

FanSelect(SNames,1,SubSNameS,1,pF,pFUnitType,pP,
pPUnitType,ResultS);

ShowMessage(Result1[1]);
ShowMessage(FloatToStr(Result2[1]))
End;

end.

为何数据未能回传呢?还是我传递参数的方法不对?(Dll肯定没有问题)请各位大师帮忙解决下哈!
 
C没学习过。如果是基础的东西请看看这个:
http://delphibbs.com/keylife/iblog_show.asp?xid=21485
http://delphibbs.com/keylife/iblog_show.asp?xid=21264
http://delphibbs.com/keylife/iblog_show.asp?xid=21502
 
我是以静态的方式调用FanSelect函数,但是根本没有返回数据,也有可能是我过程类型传递参数有错误?麻烦大师们看看,因为是第一次使用过程类型,不知道这样传递参数对不对。谢谢啦!
 
没有仔细看你的代码。
我觉得动态库的使用,最最关键的是数据类型,比如STRING 和PCHAR运用地不好的话就不会传递回数据。
 
我用于回传的参数是一个过程类型的函数指针,其所带的参数是char的数组以及Double数组(即使用指针进行传送也不成功)!
 
顶部