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

105 views Asked by At

I am very new to the .NET platform (coming from the JVM and having some limited C/C++ experience) and trying my first managed C++ class library. This is to serve as a bridge to a third-party DLL I got and I have to interface. I tried it with BridJ and Java but had no success so far, so I am now trying to write the program which uses the third-party DLL in C#.

The third-party DLL is unmanaged C++.

My ManagedBridge.h so far looks similar to this:

#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
    };
}

My ManagedBridge.cpp so far looks like this:

#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
}

}

Now, when I build this, I get no errors, and a ManagedBridge.dll is created.

I then created a C# Console application to test my DLL, added it as a reference, but I cannot access the class I exported with __declspec(dllexport). Only the namespace is shown in the object browser.

What am I missing?

1

There are 1 answers

0
Neil M On BEST ANSWER

It's

public ref class BridgedThirdPartyThing

for C++/CLI. You don't use __declspec(dllexport). Note that the class needs to be public to be visible to comsuming assemblies.