Wrapping a c#/WPF GUI around c++/cli around native c++

纵饮孤独 提交于 2019-12-24 01:53:36

问题


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.

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) Refactoring the base code in unmanaged C++ (yay for intellisense support, eh?)

2) Wrapping that base in a managed class library

3) Wrapping step 2 in a C#/WPF GUI, referencing it through interop (CLI/CLR).

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++.

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.

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.


回答1:


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).

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.



来源:https://stackoverflow.com/questions/6362434/wrapping-a-c-wpf-gui-around-c-cli-around-native-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!