![](/img/trans.png)
[英]Does Delphi and FPC have MakeWord functions (out of two bytes or chars)?
[英]Exporting overloaded functions with fpc
我需要在fpc(delphi-mode)中創建一個dll。 它工作正常 - 但由於某些原因,我想做一些事情(在一個單位)喜歡
function doSomeThing(a:type1):type2;stdcall;
function doSomeThing(a:type3):type4;stdcall;
並在庫中(使用上面的單元構建dll)
exports
doSomeThing(a:type1) name 'doSomeThingTYPE1',
doSomeThing(a:type3) name 'doSomeThingTYPE3';
語法是自解釋的,並告訴如何從DLL導出重載函數? 。 但它似乎在fpc(版本2.6.0-9 [2013/04/14] x86_64)中不可用。 有沒有機會做這樣的事情 - 或者我是否必須在我的源代碼中重命名這些功能?
您鏈接的問題討論了Delphi。 FPC不支持Delphi支持的語法,允許您導出重載的函數。
據我所知,重載函數不可導出。 雖然,我在這方面很容易出錯。 也許有一種方式,正如馬可在他的回答中提出的那樣。
大衛在另一個線程中咨詢了我,我設計了一些可編譯的東西,但不知道它是否有效。
它基於使用定義的鏈接器級別標識符導出函數,然后聲明使用不同的Pascal名稱重新導入它的外部函數。 請注意,bla和bla2甚至不必與dosomething變體屬於同一單位。
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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.