Confuzed on COM object pointers

Started by
5 comments, last by Calin 18 years ago
I have a twisted framework I build my game on. The framework has a lot of pointers to pointers. I'm trying to use smart pointers and I got really confuzed on sintax. No problem here:

//old sintax:
IDirect3DDevice9 *g_d3d_device;

IDirect3D9 *g_D3D;

//new sintax:
ATL::CComPtr<IDirect3DDevice9> g_d3d_device;

ATL::CComPtr<IDirect3D9> g_D3D;






And here comes the nightmare:

//declaration
HRESULT dhInitD3D(IDirect3D9 **p_d3d);
//definition
HRESULT dhInitD3D(IDirect3D9 **p_d3d){
   
   (*p_d3d) = Direct3DCreate9(D3D_SDK_VERSION);
  
   }

   return D3D_OK;
}
// function being called
dhInitD3D(&App1.g_D3D);


//declaration
HRESULT dhInitDevice(IDirect3D9 *p_d3d,IDirect3DDevice9 **p_device);
//definition
HRESULT dhInitDevice(IDirect3D9 *p_d3d,IDirect3DDevice9 **p_device){
HRESULT hr = S_OK;

   hr=p_d3d->CreateDevice(p_adapter,
                        p_dev_type,
                       
                        p_window,

                        D3DCREATE_SOFTWARE_VERTEXPROCESSING,

                        p_pp,
                        
                        p_device);
   

   return hr;
}
// Function being called
hr=dhInitDevice(App1.g_D3D,&App1.g_d3d_device);







I thought IDirect3D9 **p_d3d becomes ATL::CComPtr<IDirect3D9> *p_d3d but it doesn't work the code won't compile. Could anyone give me a kick off here? [Edited by - Calin on March 30, 2006 6:48:39 AM]

My project`s facebook page is “DreamLand Page”

Advertisement
ATL::CComPtr<IDirect3D9> *p_d3d; is a pointer to a smart pointer.
ATL::CComPtr<IDirect3D9*> p_d3d; is a smart pointer to a pointer.

s/sintax/syntax/g

HRESULT dhInitD3D( ATL::CComPtr<IDirect3D9>& p_d3d){   p_d3d = Direct3DCreate9(D3D_SDK_VERSION);   return !p_d3d          ? E_FAIL          : D3D_OK; }
Thanks for your replies!

Konfusius: I tried using your code. The problem is that last parameter in CreateDevice function has to be a
IDirect3DDevice9 **

From the DirectX SDK Documentation:
HRESULT CreateDevice(  UINT Adapter,  D3DDEVTYPE DeviceType,  HWND hFocusWindow,  DWORD BehaviorFlags,  D3DPRESENT_PARAMETERS * pPresentationParameters,  IDirect3DDevice9 ** ppReturnedDeviceInterface);


Trying to use your method
(
ATL::CComPtr<IDirect3DDevice9>& p_device
hr=p_d3d->CreateDevice(...,...,...,...,...,p_device);
)

fires a compile error.

My project`s facebook page is “DreamLand Page”

Using CreateDevice(...,...,...,...,...,&p_device); made the error dissapear.

My project`s facebook page is “DreamLand Page”

Do you got it working now?
Yeah, to a certain extent. I have also to replace all my other DirectX interfaces(i.e. ID3DXMesh, IDirect3DTexture9 )with CComPtr pointers and I'm still shaky on pointers.

It will take a while until I will have everything working right.

Thanks for helping out!

[Edited by - Calin on March 30, 2006 10:43:01 AM]

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement