用于LabView的本机c ++的c ++ / cli dll包装器

时间:2018-08-03 14:55:32

标签: c++ c++-cli wrapper shared-ptr labview

我正在尝试为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。

First break in debug mode (NULL ptr) 注意:InstanceHandle是shared_ptr

可以看出,变量是一个NULL指针,g_hCoreDeviceCollectoin也发生同样的情况。我想我需要用新命令实例化它,但是由于InstanceHandle是shared_ptr,因此我不确定。

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

C ++ / CLI具有称为mixed mode的强大功能。您可以在同一代码(在同一C ++ / CLI类中)中使用托管数据类型和本机数据类型。尝试直接在包装器中使用C ++编写的SDK中的对象。