Hello, I'm hoping you can help me make a smart decision. I have some code written in native C++, a full program actually--and I need to use it with C#. The application is, at the moment, very basic. It has a console user interface, and settings need to be changed via changing some code (no user interface). I've read there are at least two ways to do this, one of which is using C++/CLI and the other being creating a DLL.

The native C++ prog. makes extensive use of classes, multi-threading, and the typical things in a C++ program.

Which option would be the best (least work) for using the code in C# ? Keep in mind, I've not had much experience with creating DLL's nor with using C++/CLI.

I will appreciate any advice or opinions you may have, thank you.

Knowing nothing more about your code that what you wrote, an extremely high-level solution could look like:

1) Convert your main() function to C# in a new C# Console Application project.
2) Create a new C++ "Class Library" project.
3) Copy all of your C++ code, minus the main() function, into the new project.
4) Attempt to build the C++ library.
5) In your C# project, set a reference to the new C++ Class Library.
6) Run the C# program and see what happens.

Again, that's extremely high-level, and discounts any possible non-portable constructs that may be in the C++ code that will have to be modified/rewritten to work with the CLI. It also assumes that the main() function in your current C++ program is relatively straightforward and can be converted to C# easily.

That's the way I'd start out, at least.

Good luck!

Comments
Helpful, and interesting post.
Good suggestions.

I forgot to mention it also uses the boost library.
It doesn't build, it spouts errors about the boost library code like this:

1>c:\boost_1_45_0\boost\thread\win32\thread_primitives.hpp(314): warning C4793: 'boost::detail::win32::interlocked_bit_test_and_set' : function compiled as native :
1> Found an intrinsic not supported in managed code

When compiled with CLR support.

I'm assuming that's required? It builds fine without CLR support.

Edited 5 Years Ago by pseudorandom21: n/a

Can you please post the solution to the problem you were having? I have the same problem and would like to understand how you solved this.

Thanks

This question has already been answered. Start a new discussion instead.