Jump to content
  • Advertisement
Sign in to follow this  
EvilWeebl

Directx c++ in c#?

This topic is 3260 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
Advertisement
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
Making your GUI with C++ may not be that bad, if you use a proper framework for it. Raw Win32 is pretty cumbersome and MFC is old and busted, but I've heard good things about Qt.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!