Sign in to follow this  

Directx c++ in c#?

This topic is 3045 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 people, I have so far made some c++ code that uses directx that takes in a sprite sheet and manipulates it etc to form an animation. Now I need to make a full application with a GUI allowing a user to modify how they want the animation to appear and therefore thought using visual c# would be quick and easy despite having zero knowledge of it haha. So my problems are as such: 1. How do I run c++ source files in a c# project? 2. How do I go about implementing this c++ directx animation into say a c# forms picture box? Any very very detailed help would be much appreciated!

Share this post


Link to post
Share on other sites
possibility 1 out of many: make your C++ tool completely usable from the command line and build a C# application on top of that. This will involve simple but limited interactions between the two.

maybe you should consider converting the whole thing to C#/XNA

Share this post


Link to post
Share on other sites
You can't just add a .cpp file to a C# project and compile it...native C++ files must be compiled in a C++ project.

There's 3 ways to have managed code interop with native code:

1. PInvoke: from pretty much any managed language you can call flat C functions from a native DLL by making a function to match the signature and giving it the DllImport attribute. Unfortunately this doesn't really work for calling C++ member functions, because you have the issue of the "this" pointer and mangled names.

2. C++/CLI: this is an extension to C++ that lets you write managed code in C++ and directly interact with native C++ code in the same project or source files. Usually what you'll do is create a managed wrapper for your native types, and then the wrapper will handle calling the methods on the native type. However this is not at all a task for beginners, as there's all kinds of gotchas to be aware of.

3. COM Interop: Visual Studio can automatically generate managed wrapper assemblies from a COM type library, which lets you basically consume COM types without having to any special work on your end. However making your C++ classes COM-accessible is a ton of work, and I really doubt it's something your interested in.

Share this post


Link to post
Share on other sites
Ok well it appears I really have two options then. Either I convert directx stuff into c# and learn c# to carry on...or make the entire GUI with c++.

I do have a deadline for it soon so it might be better to just pile on with c++ instead of starting to learn another language.

Thanks for the help anyway!

Share this post


Link to post
Share on other sites

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