I have run in to this problem of converting a C++/CLI pointer to a native C++ pointer. Heres the background:
I'm writing a windows forms application using C++/CLI. The application makes call into a number of COM Interfaces. When creating an instance (inside of a C++/CLR class) of a object through the COM interface, i pass in (void**)(&provider)
as the last argument to CoCreateInstance
, as in:
HRESULT CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, (void**)(&provider));
However, i get the compiler error: cannot convert from cli::interior_ptr<Type>
to void **
.
I've done som research into this, and it looks like it is a problem of different types of pointers in C++ and C++/CLI. Anyone has any knowledge about this, and maybe a tip on how it could be fixed? Thanx in advance!
First, thanx for all your help!
As Freich suggested, i tried to use the pin_ptr
, but this instead made the compiler complaining about problems converting from interior_ptr
to pin_ptr
. If i instead try to use the interior_ptr
as in:
pin_ptr<void *> pinnedPtr = &provider;
CoCreateInstance(CLSID_MSPRProvider, NULL, CLSCTX_LOCAL_SERVER, IID_IMSPRProvider, ( void** )pinnedPtr);
I get cannot convert from interior_ptr
to interior_ptr
.
It all boils down to the problem of converting the interior_ptr
to void**
. Like this: (void**)interiorPtr
, where interiorPtr
of course is an interior_ptr
. Any ideas in this?