Home › Forums › Programming › C# Wrapper for C++ Dll
- This topic has 2 replies, 2 voices, and was last updated 14 years, 1 month ago by Anonymous.
-
AuthorPosts
-
-
21/03/2010 at 11:11 am #7668AnonymousInactive
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
-
21/03/2010 at 2:26 pm #45503AnonymousInactive
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
-
22/03/2010 at 9:56 am #45507AnonymousInactive
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!!
-
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.