Tuesday, August 05, 2008

Implementing Interfaces in C++/cli

This must be such a simple topic that its hard to google for, because I couldn't find it. So, I figured I'd blog it quickly for other .NET newcomers who've been mainly doing C#.

Given IFace.cs in dll SomeInterface.dll:
namespace Some
{
public interface IFace
{
void Express(string mood);
}
}


This would be implemented like so in DogFace.h:
#using <SomeInterface.dll>
#using <mscorlib.dll>

using namespace System;
using namespace Some;

public ref class DogFace: IFace
{
public:
virtual void Express(String^ mood); //virtual is required
};


Pretty simple, but it took me longer than I would have liked.

No comments:

Post a Comment