c++ - 用于 LabView 的原生 c++ 的 c++/cli dll 包装器
问题描述
我正在尝试为 IO Industries Core2 DVR 编写一个 c++/cli 包装器,然后 LabView 将使用它。该公司提供了一个包含所有头文件(用 c++ 编写)和 boost 库的 SDK。我已经设法构建了一个构建器,LabView 能够通过 .net 托盘看到该功能。
// ManagedProject.h
#pragma once
#include "core_api_helper.h"
#include "core_api.h"
using namespace System;
using namespace CoreApi;
namespace ManagedProject {
//Setup class
public ref class Setup
{
private:
public:
unsigned int initializeTest();
};
}
// 这是 DLL 包装器。
#include "stdafx.h"
#include "ManagedProject.h"
#include "core_api_helper.h"
#include "core_api.h"
#include "resource.h"
using namespace CoreApi;
using namespace Common;
using namespace ManagedProject;
//Global handles
//A handle to the Core Api
InstanceHandle g_hApi;
//A handle to the Core Api Device Collection
DeviceCollectionHandle g_hCoreDeviceCollection;
unsigned int Setup::initializeTest()
{
try
{
//Initialize the Core API (must be called before any other Core API functions)
//Returns a handle to the Core Api
g_hApi = Instance::initialize();
// get a collection of Core devices
g_hCoreDeviceCollection = g_hApi->deviceCollection();
unsigned int deviceCount = g_hCoreDeviceCollection->deviceCount();
return deviceCount;
}
catch (GeneralException& e)
{
e.what();
return 3;
}
}
但是,当我在调试模式下通过 Visual Studio 2015 运行 LabView 时,我遇到了以下问题,返回给 LabView 的是来自 catch 块的 3。
调试模式下的第一次中断(NULL ptr) 注意: InstanceHandle 是一个 shared_ptr
可以看出该变量是一个 NULL 指针,同样的事情也发生在 g_hCoreDeviceCollectoin 上。我想我需要用新命令来实例化它,但我有点不确定,因为 InstanceHandle 是一个 shared_ptr。
任何帮助将非常感激
解决方案
C++/CLI 有一个很棒的特性,叫做混合模式。您可以在同一代码中(在同一 C++/CLI 类中)同时使用托管数据类型和本机数据类型。尝试在包装器中直接使用用 C++ 编写的 SDK 中的对象。
推荐阅读
- angular - 如何在一个 ASP.NET Core 应用程序中使用两种不同版本的 Bootstrap
- jquery - 使用对象数组构建 jQuery 数据表
- python - 用更少的内存为 LSTM 时间序列创建数据集
- laravel - Laravel 路由冲突
- python - 使用 Selenium Python 在网站上单击复选框元素
- c# - 使用 Ext jS 将数据绑定到 Checkbox 组
- django - Bootstrap 和 Jinja - 居中图像
- java - 如果给定单个行和列的总和,如何用随机数填充 mxn 矩阵?
- react-hooks - 如何使映射项中的按钮触发另一个映射数组,单击按钮时将 id 作为键它显示显示内容
- datepicker - 带有Timepicker bsconfig的ngx-bootstrap datepicker不起作用