Oliver Spryn
Oliver Spryn

Reputation: 17348

C++/CLI Implementing a C# Interface

I have a C# interface which looks like this:

public interface ITdcConnector
{
    void Close(uint);
    void FetchRequestAsync(ManagedFetchRequest);
    UInt32 Open(String, Action<uint, ManagedFetchResponse>, out Int64);
}

I am trying to implement in C++/CLI like this:

public ref class MockTdcConnector : public ITdcConnector
{
public:
    virtual Void Close(UInt32);
    Void FetchRequestAsync(ManagedFetchRequest);
    UInt32 Open(String, Action<UInt32, ManagedFetchResponse^>^,
      [System::Runtime::InteropServices::Out] Int64%);
};

IntelliSense is giving me grief on the Open() method. It tells me: IntelliSense: class fails to implement interface member function "ITdcConnector::Open"

I've looked at a few relevant examples on implementing C# classes in C++/CLI, but no luck. Any idea on how to get the C++/cli method signature to look like the C# method?

Upvotes: 2

Views: 1061

Answers (1)

Oliver Spryn
Oliver Spryn

Reputation: 17348

So, I didn't see this until just now. I started typing the name of the C# method in the C++/cli class and IntelliSence showed the method signature it was expecting. I just needed some more ^s and virtuals.

Here is what I ended up using, for future reference:

public ref class MockTdcConnector : public ITdcConnector
{
public:
    virtual Void Close(UInt32);
    virtual Void FetchRequestAsync(ManagedFetchRequest^);
    virtual UInt32 Open(String^, Action<UInt32, ManagedFetchResponse^>^
      [Runtime::InteropServices::Out] Int64%);
};

Upvotes: 2

Related Questions