Home Forums Programming C# Wrapper for C++ Dll

Viewing 2 reply threads
  • Author
    Posts
    • #7668
      Anonymous
      Inactive

      Hi all,
      I’m writing a C# wrapper in order to use the ODE into XNA. Now the problem is that I’ve never done that and, having had a look at the ways to go, I’m quite confused. These are the options:

      – create a C# dll using PInvoke to access the methods of the C++ dll, which seems the most straight forward one; I "just" need to re-define the structs from the original code, but how do I translate this in C#??
      [code:1:1dd55558ba]struct dBase {
      void *operator new (size_t size) { return dAlloc (size); }
      void *operator new (size_t size, void *p) { return p; }
      void operator delete (void *ptr, size_t size) { dFree (ptr,size); }
      void *operator new[] (size_t size) { return dAlloc (size); }
      void operator delete[] (void *ptr, size_t size) { dFree (ptr,size); }
      };[/code:1:1dd55558ba]

      – rewrite the C++ interface using C++/CLI. It seems to me that the ODE is not a class based engine but mostly a struct based one. I’m really not too sure on how to procede with this.

      – rewrite the C++ interface using MFC++, which is the older version of C++/CLI.

      What do you suggest? I’d like to go for the most intuitive and efficient one.

      Thanks,

      Marco

    • #45503
      Anonymous
      Inactive

      My ODE is rusty, but you shouldn’t need dBase – that’s an internal structure. The ODE API operates with opaque types (dWorldID, dBodyID etc); the idea is that the calling program doesn’t need to know the layout or contents of most (if not all) of the structures used by the library. Rather (as an example) you call dWorldCreate to create a world (returns a dWorldID), the actual contents of which are never known to the calling program- to perform operations on the object you pass it as an argument to the API call which does the work internally (so dWorldStep(dWorldID, …) to step the world etc).

      So you should be able to use a technique like the one described here (I’m no .NET expert, but the article contents sound about right): http://blogs.msdn.com/jmstall/archive/2006/11/29/mashal-opaque-structs-with-intptr.aspx

    • #45507
      Anonymous
      Inactive

      It seems I have to improve my understanding of C++ as well :). Well then, I will look into that article, but it already sound like a lot less work to do.
      Thanks!!

Viewing 2 reply threads
  • The forum ‘Programming’ is closed to new topics and replies.