Jump to content
  • Advertisement
Sign in to follow this  
aviosity

Unity Converting C++ DLL Header to C#

This topic is 4150 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

Hey all, I have another post in the Alternative Game Libraries forum here, but as I thought this was a separate subject (I'm attempting to actually do this myself rather than looking for an already existing wrapper), I could use some serious hints in programming this. I'm attempting to implement a C# wrapper DLL for the FMOD Designer API/Event System. Essentially, FMOD provides a DLL called fmod_event.dll to use in programs, but unlike the fmod.dll system, only provides a C++ wrapper for the Designer API. I've already got the FMOD Ex distribution itself up and running with the C# headers they provided with no problem. I used to program in C# awhile back (a few years), but never attempted to load a DLL, let alone one in an unmanaged language like C++. I don't even know the first place to start in converting this C++ header to C#. Here's a class from the C++ header. I think F_API is declared as __declspec(dllexport) F_STDCALL in the files. This file portion is distributed with FMOD Ex under FMOD/fmoddesignerapi/api/inc/fmod_event.h:
typedef FMOD_RESULT (F_CALLBACK *EVENT_CALLBACK)  (Event *event, EVENT_CALLBACKTYPE type, void *param1, void *param2, void *userdata);

    /*
        FMOD EventSystem API
    */

    FMOD_RESULT F_API EventSystem_Create(EventSystem **eventsystem);

    class EventSystem
    {
        public :

        virtual FMOD_RESULT F_API init               (int maxchannels, FMOD_INITFLAGS flags, void *extradriverdata, EVENT_INITFLAGS eventflags = EVENT_INIT_NORMAL) = 0;
        virtual FMOD_RESULT F_API release            () = 0;
        virtual FMOD_RESULT F_API update             () = 0;
        virtual FMOD_RESULT F_API setMediaPath       (const char *path) = 0;
        virtual FMOD_RESULT F_API setPluginPath      (const char *path) = 0;
        virtual FMOD_RESULT F_API getVersion         (unsigned int *version) = 0;
        virtual FMOD_RESULT F_API getInfo            (EVENT_SYSTEMINFO *info) = 0;
        virtual FMOD_RESULT F_API getSystemObject    (System **system) = 0;

        virtual FMOD_RESULT F_API load               (const char *filename, EVENT_LOADINFO *loadinfo, EventProject **project) = 0;
        virtual FMOD_RESULT F_API unload             () = 0;

        virtual FMOD_RESULT F_API getProject         (const char *name, EventProject **project) = 0;
        virtual FMOD_RESULT F_API getProjectByIndex  (int index,        EventProject **project) = 0;
        virtual FMOD_RESULT F_API getNumProjects     (int *numprojects) = 0;
        virtual FMOD_RESULT F_API getCategory        (const char *name, EventCategory **category) = 0;
        virtual FMOD_RESULT F_API getCategoryByIndex (int index,        EventCategory **category) = 0;
        virtual FMOD_RESULT F_API getNumCategories   (int *numcategories) = 0;
        virtual FMOD_RESULT F_API getReverb          (const char *name, EventReverb **reverb) = 0;
        virtual FMOD_RESULT F_API getReverbByIndex   (const int index,  EventReverb **reverb) = 0;
        virtual FMOD_RESULT F_API getNumReverbs      (int *numreverbs) = 0;

        virtual FMOD_RESULT F_API getGroup           (const char *name, bool cacheevents, EventGroup **group) = 0;
        virtual FMOD_RESULT F_API getEvent           (const char *name, EVENT_MODE mode, Event **event) = 0;
        virtual FMOD_RESULT F_API getEventBySystemID (unsigned int systemid, EVENT_MODE mode, Event **event) = 0;
        virtual FMOD_RESULT F_API getNumEvents       (int *numevents) = 0;

        virtual FMOD_RESULT F_API set3DNumListeners  (int numlisteners) = 0;
        virtual FMOD_RESULT F_API get3DNumListeners  (int *numlisteners) = 0;
        virtual FMOD_RESULT F_API set3DListenerAttributes(int listener, const FMOD_VECTOR *pos, const FMOD_VECTOR *vel, const FMOD_VECTOR *forward, const FMOD_VECTOR *up) = 0;
        virtual FMOD_RESULT F_API get3DListenerAttributes(int listener, FMOD_VECTOR *pos, FMOD_VECTOR *vel, FMOD_VECTOR *forward, FMOD_VECTOR *up) = 0;

        virtual FMOD_RESULT F_API registerMemoryFSB  (const char *filename, void *fsbdata, unsigned int fsbdatalen) = 0;
        virtual FMOD_RESULT F_API unregisterMemoryFSB(const char *filename) = 0;

        virtual ~EventSystem(){};
    }; 


Any hints, advice, code, ANYTHING would be helpful. I really appreciate it! Thanks, Aviosity

Share this post


Link to post
Share on other sites
Advertisement
I believe some of these links may help you:

http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/
http://blogs.msdn.com/jonathanswift/archive/2006/10/02/780637.aspx
http://www.codeproject.com/csharp/dynamicinvokedll.asp
http://quickstart.developerfusion.co.uk/QuickStart/howto/doc/Interop/PInvoke_Simple.aspx

Hope this helps.

Edit: You should look into what the return values and calling conventions are as well. Try and find what FMOD_RESULT, F_API, etc are. Also see if there's anything on classes. All of the links I've provided talk about calling functions, I wouldn't know where to start with what you posted either, heh. Good luck.

Share this post


Link to post
Share on other sites
Thanks a lot for the links, they've got me started. I doubt I'll get very far by demo time, and I've informed my team as such, so we're working on a backup solution.

Thanks,
Aviosity

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!