Using mem_fun_ref with boost::shared_ptr

爱⌒轻易说出口 提交于 2019-12-06 10:37:58

Isn't the calling convention specifier a problem? Would this be OK?

void iUnk_delete(IUnknown* u) {
  u->Release();
}


return shared_ptr<IDirectDrawSurface>(dds, iUnk_delete);

std::mem_fun_ref doesn't support stdcall calling conversion as well as std::mem_fun which you could use for pointers.

You could use boost::mem_fn instead. You should define BOOST_MEM_FN_ENABLE_STDCALL to work with COM methods.

shared_ptr<IDirectDrawSurface>( dds, boost::mem_fn(&IUnknown::Release) );

And since your object has the internal reference count you could consider using boost::intrusive_ptr instead.

I know this maynot be what youa re after but just include ATLBase.h and then use the CComPtr template.

You then just use

 CComPtr< IDirect3DSurface9 > surf;
 pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &surf );

You can then copy it to another CComPtr and it handles all the AddRefs and Releases for you. Very useful template class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!