VS2019 如何创建C++/Cli程序

今天重新安装了VS2019,在创建页面愣是没找到C++/Cli的项目

解决方案:

默认安装是没有办法创建C++/Cli的

在安装选择界面,选择单个组件

输入Cli,勾选C++/Cli支持 的 其中一个,点击安装

 

安装完后,可以看到已经有CLR项目了 

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的示例,演示如何在 C++/CLI 中封装 VB.NET DLL 中的 API: 1. 在 VB.NET 中创建一个 DLL 文件 首先,在 VB.NET 中创建一个名为 "MyLibrary" 的 Class Library 项目,并在其中添加以下代码: ``` Public Class MyAPI Public Function AddNumbers(ByVal num1 As Integer, ByVal num2 As Integer) As Integer Return num1 + num2 End Function End Class ``` 然后,编译该项目并生成 MyLibrary.dll 文件。 2. 在 C++/CLI 中添加对 VB.NET DLL 的引用 打开一个 C++/CLI 项目,并在其中添加对 MyLibrary.dll 的引用。具体步骤如下: - 在 "解决方案资源管理器" 中,右键单击 "引用",选择 "添加引用"。 - 在 "添加引用" 窗口中,点击 "浏览" 按钮,并选择 MyLibrary.dll 文件。 - 点击 "确定",完成添加引用的操作。 3. 在 C++/CLI创建 public ref class 在 C++/CLI创建一个名为 "MyWrapper" 的 public ref class,用于封装 MyLibrary.dll 中的 API。具体代码如下: ``` #include "stdafx.h" #include <msclr\auto_gcroot.h> using namespace System; using namespace MyLibrary; public ref class MyWrapper { public: MyWrapper() { // 初始化 VB.NET API 对象 m_api = gcnew MyAPI(); } int AddNumbers(int num1, int num2) { // 调用 VB.NET API 的 AddNumbers 方法 return m_api->AddNumbers(num1, num2); } private: // 使用 auto_gcroot 包装 VB.NET API 对象 msclr::auto_gcroot<MyAPI^> m_api; }; ``` 需要注意的是,这里使用了 "msclr\auto_gcroot.h" 头文件,以便在 C++/CLI 中包装 VB.NET 对象。 4. 编译并使用封装的 API 将 MyWrapper 编译为 DLL 文件后,即可在其他应用程序中使用该 DLL 文件,并调用其中的 AddNumbers 方法,例如: ``` #include <iostream> #include "MyWrapper.h" using namespace std; int main() { MyWrapper^ wrapper = gcnew MyWrapper(); int result = wrapper->AddNumbers(1, 2); cout << "The result is: " << result << endl; return 0; } ``` 运行该应用程序后,将输出 "The result is: 3"。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值