c++ logic, c# gui
本文关键字:gui logic c++ | 更新日期: 2023-09-27 18:33:41
我必须用 C# 和 C++ 中的逻辑编写 GUI。如何在 Visual Studio 2010 中创建项目,以便之后不会有任何复杂情况(当我将链接两种语言时)。我需要扩展/插件/其他什么吗?
首先,你需要有两个项目,一个用于 c# gui,一个用于 c++ 逻辑。如前所述,它们可以放入相同的解决方案中。如果您已准备好使用托管C++则可以将逻辑放入类库中,UI 项目可以通过传统方式访问该类库。将 c++(甚至是非托管逻辑)打包到托管类接口中是很常见的。
因为已经讨论了C++托管代码中的逻辑。要调用托管代码中的非托管代码,您可以使用 PlaPlatform 调用服务 (PInvoke)。它allows managed code to call unmanaged functions that are implemented in a DLL
.例如,看看这个MSDN代码
// PInvokeTest.cs
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
{
[DllImport("msvcrt.dll")]
public static extern int puts(string c);
[DllImport("msvcrt.dll")]
internal static extern int _flushall();
public static void Main()
{
puts("Test");
_flushall();
}
}