Jump to content
  • Advertisement
Sign in to follow this  

Confuzed on COM object pointers

This topic is 4619 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:
HRESULT dhInitD3D(IDirect3D9 **p_d3d);
HRESULT dhInitD3D(IDirect3D9 **p_d3d){
   (*p_d3d) = Direct3DCreate9(D3D_SDK_VERSION);

   return D3D_OK;
// function being called

HRESULT dhInitDevice(IDirect3D9 *p_d3d,IDirect3DDevice9 **p_device);
HRESULT dhInitDevice(IDirect3D9 *p_d3d,IDirect3DDevice9 **p_device){




   return hr;
// Function being called

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
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


HRESULT dhInitD3D( ATL::CComPtr<IDirect3D9>& p_d3d)
p_d3d = Direct3DCreate9(D3D_SDK_VERSION);
return !p_d3d
: 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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!