Jump to content
  • Advertisement
Sign in to follow this  
AntonyCoder

[.net] Linking to a unmanaged dll (Mono C# Windows)

This topic is 4501 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Does anyone have any code snippets for how to link to a dll wrote in a unmanaged language(Bmax but it uses the same standard calling convention as C++ as it's based mingw) For example in bmax to link to a dll I'd first create a function prototype, then open the library, then assign the address of the function by name to the prototype. Is it all similar for Mono C#? If someone could just post a bit of code linking to an imaginary dll with a single static function/method I'd buy you a virtual beer and a packet of crisps:)

Share this post


Link to post
Share on other sites
Advertisement
Search for PInvoke. A Windoze example from the SDK documentation:
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int MessageBox(int hWnd, String text,
String caption, uint type);


I don't know if it works on Mono; I suspect not. You might want to head over to the Mono forums, wherever they are, and ask the experts there.

Share this post


Link to post
Share on other sites
you can import functions from a dll like this:

[DllImport("xvidcore.dll")]
private static extern int xvid_decore(IntPtr handle, int opt, ref xvid_dec_create_t param1, IntPtr param2);




uuh someone was faster... and yes, it works in mono just like in .net.

Share this post


Link to post
Share on other sites
Thanks for the suggestion but I tried DLLImport and Mono threw up a compile error on DLLimport saying it was not recongnized? Do I have to include any libs for it work?

Share this post


Link to post
Share on other sites
Well, you need to using System.Runtime.InteropServices. According to the SDK help, it's in mscorlib, so you shouldn't have to link any libraries. If it doesn't work, make sure you've done the right thing by compiling it under Windows (with csc); if it does there, check whether Mono actually supports it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!