you're right, in order to remain compatible, mono should use stdcall
convention by default on win32. (existing code, etc...)
piers.
-----Original Message-----
From: J. Perkins [mailto:***@379.com]
Sent: Thursday, December 19, 2002 11:42 AM
To: J. Perkins
Cc: 'Mono-L'
Subject: RE: [Mono-list] Mono/.NET delegate incompatibility
Hang on a minute, I answered this too soon. I'm not talking about
calling a DLL function. [DllImport] works just fine on both Windows and
Linux. I am talking about a callback function, from unmanaged -> managed
code. That is, a C# delegate passed to and called from unmanaged code
via a function pointer. Here's a usenet thread on the subject:
http://makeashorterlink.com/?C417214D2
The problem described in this thread is reversed for Mono: the callback
must use the cdecl convention. Because of this, there is no way to write
a C function that can call a delegate under both .NET and Mono. If I do
this:
int SomeCFunction(int (__stdcall *callback)(int, int, int))
{ return callback(1,2,3); }
...it will corrupt the stack when run under Mono on Windows. If I use
cdecl instead:
int SomeCFunction(int (*callback)(int, int, int))
{ return callback(1,2,3); }
...it will corrupt the stack when run under .NET. Maybe I'm missing
something (quite possible), but it appears that Mono must use __stdcall
for delegates on Windows.
I'll give you guys a chance to sanity check my rambling. If it holds up
I will file a bug.
Jason
379
Post by TumI guess the default calling convention in mono is cdecl. According
to
Post by TumMSDN, the default calling convention for dllimport should be stdcall
(which IMHO really only makes sense on windows).
You could try setting the CallingConvention property on the
DllImport to
_______________________________________________
Mono-list maillist - Mono-***@ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list