VC++ .net:未导出托管 DLL 的功能

VC++ .net: Functionality from managed DLL is not exported

我是 .NET 平台的新手(来自 JVM,C/C++ 经验有限),正在尝试我的第一个托管 C++ class 库。这是作为我得到的第三方DLL的桥梁,我必须接口。我用 BridJ 和 Java 尝试过,但到目前为止没有成功,所以我现在尝试在 C# 中编写使用第三方 DLL 的程序。

第三方 DLL 是非托管 C++。

我的 ManagedBridge.h 目前看起来与此类似:

#pragma once

#include "thirdparty.h"

using namespace System;

namespace ManagedBridge {

    class __declspec(dllexport) BridgedThirdPartyThing {

    private:
        THIRDPARTYNS::ThirdPartyThing* _delegate;

    public:
        BridgedThirdPartyThing();

        ~BridgedThirdPartyThing();

        void foo();

        // more methods
    };
}

我的 ManagedBridge.cpp 目前看起来是这样的:

#include "stdafx.h"
#include "ManagedBridge.h"

namespace ManagedBridge {

    BridgedThirdPartyThing::BridgedThirdPartyThing() {
        _delegate = new THIRDPARTYNS::ThirdPartyThing();
    }

    BridgedThirdPartyThing::~BridgedThirdPartyThing() {
        delete _delegate;
    }

    void BridgedThirdPartyThing::foo() {
        _delegate -> foo();
    }

    // similar for the other methods
}

}

现在,当我构建它时,没有出现任何错误,并且创建了 ManagedBridge.dll

然后我创建了一个 C# 控制台应用程序来测试我的 DLL,将其添加为参考,但我无法访问我用 __declspec(dllexport) 导出的 class。对象浏览器中仅显示命名空间。

我错过了什么?

public ref class BridgedThirdPartyThing

用于 C++/CLI。您不使用 __declspec(dllexport)。请注意,class 需要 public 才能对 comsuming 程序集可见。