将本机c ++的c#/WPF GUI封装在c ++/cli周围 [英] Wrapping a c#/WPF GUI around c++/cli around native c++
问题描述
这是一种复杂的情况.我正在重构(基础)的c ++,它必须同时用作CGI脚本和独立应用程序的核心.
This is kind of a complicated situation. I'm refactoring (ground-up) c++ that must be used as both a CGI script and the core of a standalone app.
不幸的是,自大学以来我还没有写过C ++,并且对c#/Java更加熟悉.因此,我将使用WPF作为GUI.根据我的研究表明,这意味着我将成为:
Unfortunately I haven't written C++ since college, and am more familiar with c#/Java. So I'm going to use WPF for the GUI. From what my research has revealed, this means that I will be:
1)重构非托管C ++中的基本代码(是对intellisense支持,是吗?)
1) Refactoring the base code in unmanaged C++ (yay for intellisense support, eh?)
2)将基础包装在托管类库中
2) Wrapping that base in a managed class library
3)在C#/WPF GUI中包装步骤2,并通过互操作(CLI/CLR)引用它.
3) Wrapping step 2 in a C#/WPF GUI, referencing it through interop (CLI/CLR).
我相信,第2步将有据可查.但是,我是从头开始的,对于如何实例化和使用在托管c ++中创建/公开的类,找不到任何具体的方法.
step 2, I am confident, will be well-documented. However, I'm starting at the top and can't find anything concrete on how to instantiate and use a class created/exposed in managed c++.
如果我有德鲁特(不需要硬核效率),我会用c#编写整个内容,但我没有选择.
I'd just write the whole thing in c# if I had my druthers (no need for hardcore efficiency), but I don't have that choice.
有人可以为我指出正确的步骤3,以便我可以开始研究它吗?我不想让任何人为我做家庭作业(可以这么说),但是我自己对此过程的研究一直没有成果.
Can someone point me in the right direction for step 3 so that I can start researching it? I don't want anyone to do my homework for me (so to speak), but my own research into this process has been fruitless.
推荐答案
如果将非托管C ++类包装在托管CLI/C ++对象中,则不需要Interop来调用托管类(Visual C ++将编译两个托管类和同一库中的非托管C ++).
If you wrap your unmanaged C++ classes in managed CLI / C++ objects, then you don't need Interop to invoke the managed classes (Visual C++ will compile both managed and unmanaged C++ in the same library).
只需将混合的托管/非托管库引用到托管C#应用程序,公开的托管对象的行为将与任何普通对象一样.
Simply reference the mixed managed / unmanaged library to your managed C# application and the exposed managed objects will behave like any normal object.
要获得一个好的起点,请查看这篇文章.
For a good starting point check out this article.
这篇关于将本机c ++的c#/WPF GUI封装在c ++/cli周围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!