Is there an alternative to using the following?
class IGraphBuilder;
public ref class Device
{
private:
IGraphBuilder* pGraphBuilder;
public:
void Configure()
{
pin_ptr<IGraphBuilder*> ppGraphBuilder = &pGraphBuilder;
HRESULT hr = CoCreateInstance(CLSID_FilterGraph,
NULL,
CLSCTX_INPROC,
IID_IGraphBuilder, (void**)ppGraphBuilder);
reinterpret_cast(ppGraphBuilder) compiles but I’m a bit confused if this is correct for this case.
If this wasn’t C++/CLI (where &NativeMember actually means interior_ptr<Type>(NativeMember)) I would simply use static_cast<void**>(&pGraphBuilder) but even after correctly casting to pin_ptr the following doesn’t compile
pin_ptr<IGraphBuilder*> ppGraphBuilder = &pGraphBuilder;
static_cast<void**>(ppGraphBuilder)
Is there any solution or am I forced to use (void**) because pin_ptr is weird?
reinterpret_cast(and thus C cast) is potentially not ok, although it may work due to the allegedly trivial layout ofpin_ptr. Indeed you have to call the conversion operator fromcli::pin_ptr<IGraphBuilder*>toIGraphBuilder**first (hence the complain from the compiler).is correct. You may want to introduce a intermediary variable of type
IGraphBuilder**first: