By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,495 Members | 1,943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,495 IT Pros & Developers. It's quick & easy.

C# Interfaces in C++?

P: n/a
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.

};

}


Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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]
- ni**************@exisconsulting.com

"Chris" <c w a n @ n o s p a m - v i g i l . c o m> wrote in message
news:eQ**************@tk2msftngp13.phx.gbl...
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.

};

}

Nov 13 '05 #2

P: n/a
Thanks Nicholas, I'll give it a try.
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:eW**************@TK2MSFTNGP10.phx.gbl...
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]
- ni**************@exisconsulting.com

"Chris" <c w a n @ n o s p a m - v i g i l . c o m> wrote in message
news:eQ**************@tk2msftngp13.phx.gbl...
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.

};

}


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.