加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

动态库的函数调用

发布时间:2020-12-15 10:01:34 所属栏目:大数据 来源:网络整理
导读:type xx = function(): string; stdcall;是什么意思解决方案 type xx = function(): string; stdcall;是什么意思 function?xx():?string; type ??xx=?function():?string;?stdcall; var ??func:?xx; begin ??Result?:=?'0'; ??@func?:=?yy('xx'); ??if?Assig

type xx = function(): string; stdcall;是什么意思解决方案

type xx = function(): string; stdcall;是什么意思

function?xx():?string;
type
??xx=?function():?string;?stdcall;
var
??func:?xx;
begin
??Result?:=?'0';
??@func?:=?yy('xx');
??if?Assigned(@func)?then
??begin
????Result?:=?func();
??end;
end;

如上:我想知道每一步代表什么意思,求大神告诉啊。其中的?yy('xx')是接口的初始化函数。
delphi? type? @fun? function()

------解决方案--------------------


function?xx():?string;?//?定义一个?xx?函数
type
??xx=?function():?string;?stdcall;//?定义一个名为xx的函数指针类型
var
??func:?xx;?//?声明一个名叫func、类型为xx的函数指针变量
begin
??Result?:=?'0';?
??@func?:=?yy('xx');//?func函数指针指向yy这个函数?
??if?Assigned(@func)?then?//?如果func成功指向yy这个函数
??begin
????Result?:=?func();?执行func这个函数指针指向的函数,并返回其返回值
??end;
end;





------解决方案--------------------
DLL动态调用就是这么弄的
函数定位?@func?:=?yy('xx');?
------解决方案--------------------

定义了函数指针,多数用于动态库的调用场合;如下示例:
procedure?TFrmFirewatcherDllTest.btnCmdStartTestClick(Sender:?TObject);
type??pStartCmd=function?(pbuff:PChar;nLen:Word):integer;?stdcall;
var
??hDll:Cardinal;
??startCmd:pStartCmd;
??arrCmd:array?[0..255]?of?Char;
??nLen:Word;
??i:Integer;
??str:string;
begin
??btnCmdStartTest.Enabled?:=?False;
??hDll?:=?LoadLibrary('..SourceDLLFirewatcherDLL.dll');
??try
????if?hDll>32?then
????begin
??????@startCmd?:=?GetProcAddress(?hDll,'START');
??????if?Assigned(?startCmd?)?then
??????begin
????????nlen?:=??startCmd(?arrCmd,?256?);
????????for?i:=?0?to?nLen-1?do
????????begin
??????????str?:=?str?+'?'+?IntToHex(?Ord(arrcmd[i]),?2?);
????????end;
????????Memo1.Lines.Add(IntToStr(?Memo1.Lines.Count+1)+?'?【开机】指令长度:'+inttostr(nLen)+?';?指令数据:'+quotedstr(?trim(?str?)?)???????)
??????end;
????end;

??finally
????FreeLibrary(?hDll?);
????btnCmdStartTest.Enabled?:=?True;
??end;
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读