假定外部程序给出的是一个函数指针,TSL也可以对它动态进行调用。是本次新增的功能。
使用说明:
TSLfunPointer:=function(p1:DataType;p2:Datetype;…):returnType;external funcPointer;
其中,funcPointer为外部函数指针,TSLfunPointer为返回结果,即为天软函数指针。
范例:
tslkrnl:=LoadlibraryA("tslkrnl.dll");//加载动态库
//获得到函数指针
Strtofloatptr:=GetProcAddress(tslkrnl,"TS_strtofloat");
//申明,得到一个TSL函数指针
Strtofloatfun:=function(s:string):double;external strtofloatptr;
//TSL调用函数指针,还可以用call之类的调用
Echo ##strtofloatfun("2.34"),"\r\n";
//加载操作系统提供的动态库,获得到模块指针
Function LoadlibraryA(s:string):Pointer;stdcall;external "kernel32.dll" name "LoadLibraryA";
//从模块指针中查找出函数的指针,即C的函数指针
Function GetProcAddress(hModule:Pointer;lpProcName:string):Pointer;stdcall;external "kernel32.dll" name "GetProcAddress";