KooKoo
KooKoo

Reputation: 451

C++ CLI Wrapper

I’ve a question about creating a C++ CLI Wrapper for a native C++ class to be used in C#.

Here is an example code:

#include "stdafx.h"

#pragma once

using namespace System;

namespace Wrapper {

    class NativeClass
    {
    public:
        NativeClass() {}
        int Add(int a, int b)
        {
            return a+b;
        }
    };

    public ref class Wrapper
    {
    public:
        Wrapper() {pNative = new NativeClass();}
        int Add(int a, int b)
        {
            return(pNative->Add(a,b));
        }
        ~Wrapper()
        {
            delete pNative;
            pNative = 0;
        }
        !Wrapper()
        {
            this->~Wrapper();
        }
        //My problem is here.
        NativeClass* GetNative()
        {
            return pNative;
        }
    private:
        NativeClass* pNative;
    };
}

This code works fine. I need to retrieve the pointer that refers the native class to use it in the other wrapper classes. However, I don’t want the function “GetNative” to be visible in C# when I’m using this wrapper class. How can I hide it?

Upvotes: 3

Views: 729

Answers (1)

Martin Ba
Martin Ba

Reputation: 38766

If the other wrapper classes are in the same assembly, make the access internal instead of public. – Roger Rowland Apr 25 '13 at 9:47

.

if they are not in the same assembly? ...

Look into friend assemblies – Sebastian Cabot Feb 1 at 15:43

Upvotes: 1

Related Questions