Jump to content
  • Advertisement
Sign in to follow this  
Calin

Confuzed on COM object pointers

This topic is 4437 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

s/sintax/syntax/g


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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!