views:

31

answers:

1

I am wrapping a native C++ library for consumption by the CLR. However, I'm running into a strange... problem?

The native library's headers look like so:

namespace Foo {
    class Bar {
    public:
        Bar();

        //etc...

    };
}

So, to consume this class, I have my own class definition:

#include "Foo/Bar.h"

namespace FooNet {
    public ref class Bar {
    private:
        Foo::Bar * m_Impl;

    internal:
        Bar(Foo::Bar *);

        //etc...

    };
}

And, that all works great. However, when I reference the resulting assembly into a C# project (for example) and look at the object browser, I notice that it contains not only my CLR classes (FooNet::Bar), but also the native classes (Foo::Bar) too!

I'm not particularly enthusiastic about exposing the native classes, since they use pointers and std::strings and other .NET unfriendly stuff, so is there any way to stop this from happening?

Edit: Things I learned today:

  1. The object browser shows all namespaces in the solution, not in just whatever project you happen to be looking at.
  2. Native C++ classes are not exposed in managed assemblies.
+1  A: 

Most likely the native classes are listed in the metadata for the benefit of managed debuggers, but they should be marked internal and not usable by consumer code.

Ben Voigt
Oh wow I feel stupid. The test project was part of the same solution as the C++/CLI library, and so of course it showed both.
Mike Caron