Jump to content

C# cdecl callback?


Josh
 Share

Recommended Posts

Is there any way at all to declare a callback function in C# that uses the cdecl calling convention?

 

Try something like this.

 

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]

public delegate void MyDelegate();

 

if using this you'll also want to look into Marshaling e.g.

 

Marshal.GetFunctionPointerForDelegate(Delegate d)

//Converts a delegate into a function pointer that is callable from unmanaged code.

 

Marshal.GetDelegateForFunctionPointer(IntPtr ptr, Type t)

// Converts an unmanaged function pointer to a delegate

 

I needed to use these when calling native functions from the engine.dll for my LEControl. It's how I finally got the GetSize and MakeCurrent Delegates to work properly. These function are under the System.Runtime.InteropServices namespace.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...