[fpc-pascal] How to call lib routines with cdecl calling convention with win32 app?

Coco Pascal coco.pascal at xs4all.nl
Sun May 31 20:05:49 CEST 2009


Jonas Maebe schreef:
>
> On 31 May 2009, at 15:28, Coco Pascal wrote:
>
>> Marco van de Voort schreef:
>>> In our previous episode, Coco Pascal said:
>>>
>>>> I have a library with udf routines using the cdecl calling 
>>>> convention, required by Firebird. This seems to work well on win32.
>>>
>>> How exactly?
>>>
>>
>> ?
>>
>> function Y_Odd(const AValue: Int64): LongInt; cdecl; export;
>> begin
>> if Odd(AValue) then
>>   Result := -1
>> else
>>   Result := 0;
>> end; {Y_Odd}
>>
>> exports
>>
>> Y_Odd;
>>
>> This works fine with Firebird. If I declare the stdcall calling 
>> convention Firebird can't find its entrypoint.
>
> cdecl automatically enables C-compiler-compatible name mangling for 
> exported procedures. stdcall doesn't. So it's normal that Firebird 
> does not find the entrypoint when using stdcall, as it does not 
> support FPC-style name mangling.
>
> There is no way to get C name mangling without the calling convention, 
> so you have to manually declare an alias in that case. E.g.,
>
>> function Y_Odd(const AValue: Int64): LongInt; cdecl; alias: '_Y_Odd'; 
>> export;
>
> Whether or not you need an extra underscore before the alias name 
> depends on the target platform. Win32 requires one.
>
I tried
function Y_Odd(const AValue: Int64): LongInt; cdecl; alias: '_Y_Odd'; 
export;
and
function Y_Odd(const AValue: Int64): LongInt; cdecl; alias: '__Y_Odd'; 
export;
but still I get the message entrypoint of 'Y_Odd' could not be found in 
'libyfbudf.dll'



More information about the fpc-pascal mailing list