> -----Original Message-----
> From: Mattias Sj�gren [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, January 27, 2004 3:01 PM
> Subject: Re: Callbacks from unmanaged code
> 
> 
> - The CRT functions use the cdecl calling conventions. You should set 
> CallingConvention.Cdecl in the fread() DllImport attribute.
> 
> - If the callback function is supposed to use the cdecl 
> convention too, you 
> have to fix that (which is non trivial). Delegates are 
> marshaled to stdcall 
> function pointers by default.

I'd put my money on this one.  I worked around this sort of problem in the past with a 
little MC++ code.  Essentially, Pinvoke to an MC++ assembly and pass it the delegate 
you managed code wants to be called on.  In the MC++ code, setup a callback that uses 
the CDECL calling convention.  When the unmanaged code calls the MC++ callback, it can 
then call Invoke on the delegate.  It was actually pretty simple to do it this way.  
As much as I hate the MC++ syntax and other idiosyncrasies, MC++ can be a real 
lifesaver at times.  :-)

--
Keith

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to