I have a Windows Runtime component in which all of my classes need to expose a handle internally:
private interface class IHandleContainer {
IntPtr GetHandle();
}
namespace Foo {
public ref class Bar: IHandleContainer { ... }
public ref class Baz: IHandleContainer {
internal:
virtual IntPtr GetHandle() = IHandleContainer::GetHandle;
}
}
I don't need IHandleContainer to be public, but I do need IHandleContainer to be on the interface list so that each of my internal objects can be safe_cast<IHandleContainer>
successfully.
Being outside of a namespace, IHandleContainer
should not be emitted to metadata, but should have a COM GUID associated with it and by listing it on the ref class's interface list, CX should be able to wire up the correct response to QueryInterface. Structurally, everything should "just work." But the compiler isn't cooperating:
error C3991: 'Foo::Baz': cannot implement a non-public or nested interface 'IHandleContainer'