Newton and .NET?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Newton and .NET?

Postby Leadwerks » Fri Jan 16, 2009 7:50 pm

Newton's callbacks all use the CDECL convention. I was wondering if this caused any problems with .NET, because as I understand it, .NET does not support the CDECL convention. Any information on this? I have run into a similar issue with my own engine, and I'd rather not switch all the callbacks to _stdcall.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Newton and .NET?

Postby Julio Jerez » Sat Jan 17, 2009 12:29 am

newton uses CDECL, you can see it in the header

Code: Select all
#ifdef __cplusplus
extern "C" {
#endif


forces a pure c interface regaless what option you set on in your compiler, which I am sure all laguage support.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton and .NET?

Postby martinsm » Sat Jan 17, 2009 8:58 am

.NET supports any of native callback conventions (cdecl, stdcall, fastcall, thiscall). See here: http://msdn.microsoft.com/en-us/library ... ntion.aspx
Basically you should write following code for umanaged function pointers:
Code: Select all
[UnmanagedFunctionPointer(CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public delegate void NewtonBodyDestructor(IntPtr body);

[DllImport("newton.dll", CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern void NewtonBodySetDestructorCallback(IntPtr bodyPtr, NewtonBodyDestructor callback);
martinsm
 
Posts: 86
Joined: Mon Dec 19, 2005 3:15 pm
Location: Latvia


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 12 guests