使用fpc导出重载函数 [英] Exporting overloaded functions with fpc

查看:135
本文介绍了使用fpc导出重载函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在fpc(delphi模式)中创建一个dll。它工作正常 - 但由于某些原因,我想做一些事情(在一个单位),如

I need to create a dll within fpc (delphi-mode). It works fine - but for some reasons, I want to do something (in a unit) like

function doSomeThing(a:type1):type2;stdcall;
function doSomeThing(a:type3):type4;stdcall;

和图书馆(用于使用上面单元构建dll)

and in the library (for building the dll using the unit above)

exports
    doSomeThing(a:type1) name 'doSomeThingTYPE1',
    doSomeThing(a:type3) name 'doSomeThingTYPE3';

语法是自明的,在如何从DLL导出重载函数?但是似乎在fpc(x86_64的版本2.6.0-9 [2013/04/14])中不可用。有机会做这样的事情吗?或者我必须重命名我的源代码中的函数?

The syntax is self explanatory and is told in How to export Overload functions from DLL? . But it seems to be unavailable in fpc (version 2.6.0-9 [2013/04/14] for x86_64). Is there a chance to do something like that - or do I have to rename the functions within my source?

推荐答案

David咨询了我在另一个线程中,我设计了一些编译,但不知道它是否可行。

David consulted me in another thread, I devised something that compiles, but don't know if it works.

它基于使用定义的链接器级别标识符导出函数,然后声明使用不同的Pascal名称重新导入外部函数。请注意,bla和bla2甚至不必与dosomething变体在同一单位。

It is based on exporting the function using a defined linker level identifier, and then declaring an external function reimporting it with different Pascal names. Note that bla and bla2 doesn't even have to be in the same unit as dosomething variants.

library testdll; 

{$mode delphi}
type 
   type1=integer;
   type3=char;
   type2=smallint;
   type4=widechar;

function doSomeThing(a:type1):type2;stdcall; overload; [public, alias:'bla'];
begin
  result:=a+1;
end;

function doSomeThing(a:type3):type4;stdcall; overload; [public, alias:'bla2'];
begin
  result:=widechar(ord(a)+1000);
end;

procedure bla; external name 'bla';
procedure bla2; external name 'bla2';
exports
    bla name 'doSomeThingTYPE1',
    bla2 name 'doSomeThingTYPE3';

end.

这篇关于使用fpc导出重载函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆