简体   繁体   English

可能吗? c#中的GUI,C ++中的app

[英]Is it possible? GUI in c# , app in C++

Is it even possible to create GUI layer in C# and rest of application in C++? 是否有可能在C#中创建GUI层,在C ++中创建其余的应用程序? If I am not wrong one of antyvirus software had GUI made in Delphi. 如果我没错,其中一个antyvirus软件在Delphi中制作了GUI。 How it could be done ? 怎么做?

If you write your business logic in C++/CLI, and your UI in C#, it shouldn't be a problem. 如果您使用C ++ / CLI编写业务逻辑,并使用C#编写UI,那么它应该不是问题。 If you want to write in pure ANSI C++, you might have to write C++/CLI wrappers around the objects you want to expose to C#. 如果要使用纯ANSI C ++编写,则可能必须围绕要向C#公开的对象编写C ++ / CLI包装器。

You have several options for doing it, including: 您有多种选择,包括:

  1. Use P/Invoke to call into the C++ DLL from C#. 使用P / Invoke从C#调用C ++ DLL。
  2. Expose a COM interface from the native code, and call it from C# using COM interop . 从本机代码公开COM接口,并使用COM interop从C#调用它。
  3. Write a native Windows service and call into it from managed code. 编写本机Windows服务并从托管代码调用它。
  4. Use C++/CLI to write a managed library in C++, which you can easily link to from C#. 使用C ++ / CLI在C ++中编写托管库,您可以轻松地从C#链接到该库。

If you're starting from scratch, option 4 is probably your best option. 如果您从头开始,选项4可能是您的最佳选择。 (Aside from just writing the whole thing in C#, that is.) The first three options all involve some additional wrangling and overhead, and probably aren't worth the hassle if you don't have a compelling reason such as needing to interact with an existing native library or having some need for a service-oriented architecture. (除了用C#编写整个内容之外,就是这样。)前三个选项都涉及一些额外的争论和开销,如果你没有令人信服的理由,例如需要与之交互,可能不值得麻烦现有的本机库或者需要面向服务的体系结构。

在c ++ dll中编写app逻辑,然后使用c#中的pinvoke与dll对话。

See this answer . 看到这个答案 It seems to answer your problem 它似乎回答了你的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM