[Mono-devel-list] Callling convention for interop call-backs
Karl Waclawek
karl at waclawek.net
Tue Jan 20 13:26:00 EST 2004
----- Original Message -----
From: "Liyu Liu" <liyul at hotmail.com>
> There are two issues with interop:
> 1. should winapi be cdecl or stdcall?
> 2. Can mcs be extended to support specifying call conventions in delegate as
> an extension to C#?
>
> There are only two call conventions supported in .net, --cdecl or stdcall.
> For Microsoft implementation, winapi is stdcall on win32 and cdecl on CE.
I think anything that calls itself winapi should follow MS' example.
> The fastcall is almost never used. Currently mono on win32 take default
> winapi as cdecl which created compatibility problems. Any assembly
> containing P/Invoke working with mono, like Mono.Data.SqliteClient etc,
> cannot work with Microsoft .net runtime without source code change and
> recompilation. Also same vice versa.
Not good.
> Microsoft's csc doesn't have support for cdecl for callback, thus people has
> to be resorted to IL hack to change such
>
> .method public hidebysig virtual instance int32
> Invoke(native int o,
> int32 argc,
> int8** argv,
> int8** colnames) runtime managed
> {
> } // end of method SqliteCallbackFunction::Invoke
>
> to
> .method public hidebysig virtual instance int32
> modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)
> Invoke(native int o,
> int32 argc,
> int8** argv,
> int8** colnames) runtime managed
> {
> } // end of method SqliteCallbackFunction::Invoke
>
> This should be relatively easy to support in mcs and mono.
I would think so too.
> It is a breaking change. But seemed to us best way is to extend mcs to
> support cdecl callback and change mono to use stdcall as default for winapi
> on win32. This will force all P/Invoke done with mono to change to use cdecl
> explicitly. But the benefit is final assemeblies working without any hitch
> or changes across linux/win32. There will also be no need of IL hacks.
You have *my* vote.
Instead of just supporting cdecl, why not add an attribute that
allows to specify any of the calling conventions for delegates?
Karl
More information about the Mono-devel-list
mailing list