3

I have a numerical library coded in C++.

I am going to make a UI for the library. I know some MFC. So one solution is to use MFC and make a native application.

The alternative is C#. I know nothing about C#. But I think it should be easy to learn.

Some tutorial for mixed programming of C++ and C# would be very helpful to me.

Thanks!

Yin

Yin Zhu
  • 16,980
  • 13
  • 75
  • 117

6 Answers6

8

I would recommend using Windows Forms or WPF via C# for your GUI.

Take your numerical library, and use C++/CLI to make a .NET wrapper for it. This makes it trivial to use from C# (it looks like any other C# library).

I highly recommend Nishant Sivakumar's C++/CLI articles on CodeProject for learning about C++/CLI and how to wrap C++ libraries. They're fairly well written.

MSDN is a good reference for how to use Windows Forms from C#.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
3

Write your GUI in C# using WinForms or WPF, and call your native code through Platform Invoke.

Instead of P/Invoke, you might want to consider C++/CLI to make a .NET wrapper for your native library.

IMHO using C# is MUCH more easier than MFC, so you are on the right track.

Community
  • 1
  • 1
Massimiliano
  • 16,770
  • 10
  • 69
  • 112
  • 1
    P/Invoke is difficult if it's a true C++ library. You almost have to have a C API for your library to use it. C++/CLI is much more expressive. – Reed Copsey Nov 13 '09 at 18:24
  • Depends on the interface of his C++ library, certainly. If it is simple and short, P/Invoke will do. – Massimiliano Nov 13 '09 at 18:27
1

You can use C# very easily to make the UI. You'll need to write a simple wrapper class to call your unmanaged dll, but that is straightforward. check out the msdn page on that subject

TheSean
  • 4,516
  • 7
  • 40
  • 50
0

Go with C#. MFC is somewhat dated, so if you need to learn something - go for newer technology, do not waste your time with MFC. I'd go for WPF, learning curve is rather steep, but its fun.

BostonLogan
  • 1,576
  • 10
  • 12
0

I'd suggest looking into SWIG. You can write the core part of your code in C++ as a dll, then have a C# UI link against it.

Stephen Newell
  • 7,330
  • 1
  • 24
  • 28
0

If you have the source to your C++ numerical library, you can modify it to compile as C++/CLI then you can link to it just like any other .NET library. It shouldn't require a large amount of work to modify the source with #defines for C++/CLI conditional compiling.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291