question

DanielS-1788 avatar image
0 Votes"
DanielS-1788 asked ·

Creating a GUI based on C++ library - best options?

Hello,
I've searched for information on this topic and I've not settled on a satisfying path forward.

I have several C/C++ libraries with specialized classes and variables. I am trying to figure out what is the best way to build a GUI.

I have experience with python/C# GUI creation, and usually stick to Python because it's faster and usually someone has written wrappers for a lot of APIs. The GUI does need to save variables (eg. as class members) and interpret data from user and output data to user in the form of strings or integers.

For APIs built on C++ I've explored a few options:

1) Use CLI/C++
Initially I thought this allows to directly combine C++ code within the .NET framework without having to write any wrappers or marshal data. As I dove deeper it seems that it's not quite that trivial. I would need a pretty good reference but also to understand if it's even worthwhile to learn this.

2) Use C# and wrap the C++

3) Use Python and wrap the C++

I really like how powerful Visual Studio is so I'm now thinking of doing 2), and suspect that I'm wasting my time with 1). This is something that I'll be doing very often so I might as well obtain this skillset (a lot of the instrument APIs that I use are C/C++ based).

Thanks for checking this out.

dotnet-csharpc++dotnet-runtimewinapi-ui
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JeanineZhang-MSFT avatar image
0 Votes"
JeanineZhang-MSFT answered ·

Hi,

c++/cli is a great language for writing a large component which interops between native and managed code.And Provides a fast(er) conversion path from a purely native C++ code base to a purely managed one.

If you want to use c++ api in c# code, as far as I'm concerned, you couldn't achieve it without c++/cli.

You could use P/Invoke to call functions in c++ dll. You could also try to use c++ com Interop. For more details I suggest you could refer to the links:
https://docs.microsoft.com/en-us/cpp/dotnet/calling-native-functions-from-managed-code?view=msvc-160
https://docs.microsoft.com/en-us/cpp/dotnet/native-and-dotnet-interoperability?view=msvc-160

About Python, I suggest you could post the related threads on the Python forum.

Best Regards,

Jeanine



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I've been doing more reading and I've tried to find a good guide on CL/C++ that teaches it from the ground up in detail. I think you are right, this might be the best option here.

0 Votes 0 ·

@DanielS-1788


I suggest you could start from this Doc:.NET programming with C++/CLI


0 Votes 0 ·
SimpleSamples avatar image
0 Votes"
SimpleSamples answered ·

See my Managed C++ Wrapper For Unmanaged Code. You could develop a GUI using C# then use C++/CLI to interface with C++. It is good that you want to make an investment by learning appropriate technology. The advantage of using C# is that Microsoft did not design .Net to work well with C++ but otherwise .Net is good for GUI development.

Also note that I see both terms, C++/CLR and C++/CLI, that I think are the same thing. My article uses the terms Managed C++ and C++/CLR but the standard is C++/CLI.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.