Sign in to follow this  

c# using a c++ engine

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

I have a c++ engine, and im intrested in making some sort of mesh viewer in c#, so with my engine running inside my c# application and using the c++ code. is this possible? how would i go about it? currently my engine compiles in to a lib (not a dll).

Share this post


Link to post
Share on other sites
Kinda [wink]

Trouble is templates. You can only define template instantiations and rename them for SWIG, since most other languages do not have a concept like templates:


%template(ArrayOfInts) Array<int>;


Plus operators must be renamed, which is also because of 'limitations' in other languages:


%rename(IsEqualTo) operator ==;
%rename(IsUnequalTo) operator !=;
%rename(IsLessThan) operator <;
%rename(IsMoreThan) operator >;
..etc...


Other than that it's quite a usefull tool.

cu,
CipherCraft

Share this post


Link to post
Share on other sites
Quote:
Original post by supagu
for my engine you mean?
to convert my managed code it is just some project options i assume?

Oh goodness no. You basically have to partially rewrite it.

Don't do it - terrible idea.

Using C# isn't a bad idea if you're calling your DLL-ified C++ engine. If you can pull it off, it'll probably work quite well.

The other alternative is to use a C++ windowing system, possibly through a language like Python (I recomend wxWidgets).

Share this post


Link to post
Share on other sites
I wrote a managed C++ wrapper for my engine in a night and hooked it to a C# application, it's quite simple actually. You can either write it by hand or try using SWIG to generate the wrapper.

Share this post


Link to post
Share on other sites
You can use P/Invoke to call functions in C++ DLLs, much like the Tao Framework makes class wrapper functions to OpenGL and SDL for use with .NET languages like C#. You can even make sequential class structures in C# to match up to the class interface you made in C++ held in the DLL.

To call a C++ function in a DLL file, you use the DLLImport attribute:
[DllImport("CppEngine.dll", ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static extern bool Initialize(string windowTitle, int width, int height);
The P/Invoke is very smart in converting various data formats back and forth. For example, your C++ function could take a char* and in C# you could pass in a string and P/Invoke will translate it for you [wink]. I've never tried SWIG before, I should try it out.

Share this post


Link to post
Share on other sites

This topic is 4483 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this