passing unmanaged pointers

Q

quat

I have two unmanaged pointer in a managed form class:

IDirect3D9* d3dObject;
IDirect3DDevice9* d3dDevice;

In a member function of the form, I call:

d3dObject->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
(HWND)hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
d3dPP,
&d3dDevice));

I get the error:

error C2664: 'IDirect3D9::CreateDevice' : cannot convert parameter 6 from
'cli::interior_ptr<Type>' to 'IDirect3DDevice9 **'
with
[
Type=IDirect3DDevice9 *
]
Cannot convert a managed type to an unmanaged type
 
B

Bruno van Dooren

IDirect3D9* d3dObject;
IDirect3DDevice9* d3dDevice;
In a member function of the form, I call:

d3dObject->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
(HWND)hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
d3dPP,
&d3dDevice));

I get the error:

error C2664: 'IDirect3D9::CreateDevice' : cannot convert parameter 6 from
'cli::interior_ptr<Type>' to 'IDirect3DDevice9 **'
with
[
Type=IDirect3DDevice9 *
]
Cannot convert a managed type to an unmanaged type

have a look at
http://www.codeproject.com/managedcpp/interiorpointers.asp
http://www.codeproject.com/managedcpp/pinnedpointers.asp

<quote>
from the article text:
You can see how we can pass both interior pointers as well as native
pointers to the same function; this is because native pointers automatically
convert to interior pointers. [Note that interior pointers cannot convert to
native pointers]
</quote>

I don't have the D3D SDK on my machine, but I can do something like this in
a managed app:

#pragma unmanaged
class Test
{
public:
int j;
Test(int i)
{
j=i;
}
};
void fun(Test ** item)
{
*item = new Test(1);
}
#pragma managed

//managed code here
Test* bla;
pin_ptr<Test*> pptr = &bla;
fun(pptr);

another solution is to wrap all your unmanaged D3D stuff in a wrapper class
that keeps all unmanaged stuff inside.
Note: I was able to compile my example with and without pinning the pointer,
so I don't know why your situation is different.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top