Given the following test interface (C#):
public interface ITest
{
UInt32 Simple(UInt32 someArg);
byte* Read(UInt32 count);
void Write(byte* buf, UInt32 count);
byte[] ReadArray(UInt32 count);
void WriteArray(byte[] buf);
}
Can I implement this interface in c++/cli? I’ve tried a million different ways; currently I have this:
typedef unsigned __int32 uint32;
typedef unsigned char byte;
public ref class CTest : public ITest
{
virtual uint32 Simple(uint32 someArg);
virtual byte * Read(uint32 count);
virtual void Write(byte * buf, uint32 count);
virtual System::Array<byte>^ ReadArray(uint32 count);
virtual void WriteArray(System::Array<byte>^ buf);
}
The VC2010 compiler complains bitterly about all of the methods except CTest::Simple, claiming I haven’t implemented the interface.
Can someone show me the c++/cli magic to implement an interface that passes either byte* or byte[] (preferably both)? I’m at my wit’s end…
The following compiles:
Your main problem is the fact that your
CTestmember functions are private and thus ineligible to implement the interface. The other problems are mostly related to usingSystem::Array<>rather thanarray<>(which is short forcli::array<>).