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

Daniel S 1 Reputation point
2021-03-02T20:57:59.027+00:00

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.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,420 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,232 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,526 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,118 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,106 Reputation points Microsoft Vendor
    2021-03-03T02:53:08.917+00:00

    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://learn.microsoft.com/en-us/cpp/dotnet/calling-native-functions-from-managed-code?view=msvc-160
    https://learn.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. Sam of Simple Samples 5,516 Reputation points
    2021-03-03T18:47:07.723+00:00

    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.

    0 comments No comments