动态库的函数调用

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('..\SourceDLL\FirewatcherDLL.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;

  • 0
    点赞
  • 0
    收藏 更改收藏夹
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云中雁012345

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值