开发者

Native namespace exported in C++/CLI project?

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜