Hi all.

I have a need to use native/C++ code in C# application. I basically want the lower level functionality of C++ with a good looking C# GUI.

Calling native functions from C# via Dllimport is not what I want to do. The native code will need to be running constantly in a tight loop in its own thread and also be able to modify UI objects such as a TextBox or DataGridView via a managed delegate method.

I began hastily testing a C++ CLR project, and what I found was that the IDE (visual studio 2010) had no intelisense, so had to try to build the project before finding any warnings or errors and there was also no preview of what members were available in a class either managed or unmanaged. So I quickly realized rhis would be a nightmare and so tried visual studio 2015 community, which has no option to create a C++ CLR winforms project.

I'm looking for direction to the best non unnecessarily convoluted option.

I seen a comment here which says "You can mix C++ with C# trivially. Use C# for the Winforms and take advantage of the incredible development tools, and use C++ for the cpu intensive sections. That may or may not include graphics." which sounds great and simple if only it were backed up with some evidence linkage.

I'm hoping someone has first hand experience with this and can offer some guidance, but as always all comments and suggestions are very welcome.

Recommended Answers

All 2 Replies

Did you try to incorporate c++ code into your C# code using the unsafe keyword?
You also have to mark the unsafe option in your project properties, but I forgot where exactly. It can't be difficult to find I guess. Hope it helps a bit.

To be honest I had no idea that, that might be possible, because nothing like that came up in my search.

Thank's, that would be marvellous if it works.

EDIT:
Unfortunately, it appears unsafe keyword is only for use with primitive types, I need to use many C++ #includes containing many different non primitive structures.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.