The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Using a C/C++ DLL in a Visual Studio 2010 C# program!

SikarianSikarian Registered User regular
edited November 2010 in Help / Advice Forum
I'm trying to write a game in the OGRE graphics engine, specifically using the MOGRE wrapper that lets you write it in C#.

The wrapper works great, but I run into problems trying to find libraries and other tools to use with the program. Normally using other dll's wouldn't be a problem because the are in C++, and OGRE is normally in C++, so you just import the headers and go.

Perfect example is a library called Thermite 3D that does Voxel technology. Now, there PolyVox is open source, so I can get ahold of the C++ source....is there anyway I can compile a dll that can just be referenced in my C# project and use the functions in the library?

Or am I better off trying to learn C++ and write this whole thing in that.

Sikarian on

Posts

  • bowenbowen Sup? Registered User regular
    edited November 2010
    C++ DLLs are tricky. C DLLs are okay. If you need to access classes, you're in for a world of hurt. Can you verify you don't need to access classes?

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    edited November 2010
    Here you go.

    http://www.pinvoke.net/

    This is C++ specific:
    Using C++ Interop

    If this is performance critical, you're going to probably need to write it in managed C++. PInvoke is a noticable performance hit.

    Kakodaimonos on
  • SikarianSikarian Registered User regular
    edited November 2010
    No idea if I'd need to access classes or not, never used this library before.

    I've tried pInvoke.net but unfortunately it seems the DLL I'm trying to use is not in their database :(

    and yeah I've looked at using the Interop stuff like "extern "C" int __stdcall MessageBeep(int);",

    however it seems I'd have to dig through the source and add an external for every single function. Yikes. Performance critical too, needed for graphics rendering.

    Ah well, I'll see what I can rig up

    Sikarian on
  • bowenbowen Sup? Registered User regular
    edited November 2010
    The extern stuff is, without a doubt, the fastest way to do it. You add one for each function you do use. So as your app grows, the amount of functions you have declared may grow too. If you can get ahold of the source, you can pretty much just compile it as a CLR enabled DLL and be done with it.

    Someone in your position would be better off writing their logic and such in C++ and wrapping it around the OGRE/module code and then using C# for the GUI if you need one.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Sign In or Register to comment.