Sign in to follow this  

Putting my rendering class (C++) in a DLL for use with other programs (in C# maybe)

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

Is this possible? I've never made a library. I suppose it's not important that it's a dynamically-linked one. It just needs to be something that I can somehow include in different projects in different languages. For instance, my game (written in C++) would use it for all of its rendering tasks, and my level editor (C#) would use it to display the level being created. If both programs use the same library, then I can make sure that things look consistent in each.

Share this post


Link to post
Share on other sites
To make C++ dlls that you can use from .NET languages (including C#), do a gamedev search on the phrase "CLI"

Share this post


Link to post
Share on other sites
If I used C++\CLI to write the library, will I be able to use it with a program written in unmanaged C++?

Share this post


Link to post
Share on other sites
If you want to go that route (using the same dll between C# and C++), then lookup "pinvoke" instead; this technique allows you to import specific C++ functions from dlls into C#/.NET. My personal experience with pinvoke is that it's less friendly toward generalized C++/OO behavior (i.e., limits you to C-style), but that could just be that I don't have as much experience with it as with CLI.

Note that you can always create a C++ static lib of your renderer, and then create a CLI dll referencing the C++ static lib and exposing the essentials to C#. Other C++ based projects can then reference the C++ static lib, while your C# apps would reference the CLI dll. The reason for doing this would be that a C++ static lib is simple to make, and CLI (might be) more expressive for exposing objects and such to C#. Someone might want to correct me though on my understanding of P/Invoke vs. CLI.

Share this post


Link to post
Share on other sites
Thanks! It sounds like the static lib route will be easiest. Do you by chance have any info on how I would create the CLI DLL? And must it be a DLL or is there a .NET static lib that I can make?

Share this post


Link to post
Share on other sites
To create the CLI dll you'll need to create a new project in visual studio, I believe you create a "Class Library" (In VS 2005, it's New Project -> Visual C++ -> CLR -> Class Library), but you might be able to start from a CLR Empty Project as well. There's no .NET static lib equivalent.

You'll want to read up a bit on C++/CLI, I would search for "CLI" like I mentioned, that should provide quite a few links. I believe there are various journals here by veteran GameDev'ers describing useful tips and tricks. You might also look at the SlimDX project as I believe it uses C++/CLI extensively to expose the C++ DirectX API to C#/.NET.

Share this post


Link to post
Share on other sites
Sign in to follow this