C# Interfaces in C++?

C

Chris

Hello,

I'm creating a small plugin interface for my future .NET DLL's. This
interface is written in C# primarily for C# dlls. However, in one
particular instance, I have to plugin a C++ dll. How do I use the following
interface that is written in C# in C++ (I have limited experience with VC++
and am just learning .net)?

Thanks in advance!

Chris

using System;
namespace PlugIn

{



public interface IPlugin

{

Int32 Add(Int32 a, Int32 b);

string Name{get;set;}

IPluginHost Host{get;set;}

}

/// <summary>

/// The host

/// </summary>

public interface IPluginHost

{

bool Register(IPlugin ipi);

}

}

In the .h file of the C++ project, do I just add the ": public IPlugin"
clause to the class definition? What else is necessary?

// test.h
#pragma once

using namespace System;

namespace test

{

public __gc class Class1 : public IPlugin

{

// TODO: Add your methods for this class here.

};

}
 
N

Nicholas Paldino [.NET/C# MVP]

Chris,

The only way to access this in C++ is to either use Managed Extensions
in C++, in which case you have access to all unmanaged types, or you will
have to export the interface as a COM interface, and have your C++ code
create a COM component that implements the interface.

Hope this helps.
 
C

Chris

Thanks Nicholas, I'll give it a try.


Nicholas Paldino said:
Chris,

The only way to access this in C++ is to either use Managed Extensions
in C++, in which case you have access to all unmanaged types, or you will
have to export the interface as a COM interface, and have your C++ code
create a COM component that implements the interface.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Chris said:
Hello,

I'm creating a small plugin interface for my future .NET DLL's. This
interface is written in C# primarily for C# dlls. However, in one
particular instance, I have to plugin a C++ dll. How do I use the following
interface that is written in C# in C++ (I have limited experience with VC++
and am just learning .net)?

Thanks in advance!

Chris

using System;
namespace PlugIn

{



public interface IPlugin

{

Int32 Add(Int32 a, Int32 b);

string Name{get;set;}

IPluginHost Host{get;set;}

}

/// <summary>

/// The host

/// </summary>

public interface IPluginHost

{

bool Register(IPlugin ipi);

}

}

In the .h file of the C++ project, do I just add the ": public IPlugin"
clause to the class definition? What else is necessary?

// test.h
#pragma once

using namespace System;

namespace test

{

public __gc class Class1 : public IPlugin

{

// TODO: Add your methods for this class here.

};

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top