English 中文(简体)
我如何使用——com_ptr_t?
原标题:How do I use _com_ptr_t?
  • 时间:2012-04-14 13:07:12
  •  标签:
  • c++
  • com

Say I有一个拥有的班子:

class Thing
{
public:
    Thing()
    {
        D3D11CreateDevice(..., &device, ...);
    }
    ~Thing()
    {
        device->Release();
    }
private:
    ID3D11Device* device;
};

根据我的理解,我可以使用<代码>_com_ptr_t<>/code>,确保删除该物体,而无需我明确打上<代码>Release(<>。 不过,问题在于,我可以列举该模板的正确概要。

我几乎找不到任何关于<代码>_com_ptr_t<>/code>的信息,我可以找到答案的最近一点是,(日本) 1。 在Syntax之后,我收到了编辑方面的错误:

private:
    //ID3D11Device* device;
    _com_ptr_t <_com_IIID<ID3D11Device, &__uuidof(ID3D11Device)>> device;

error C2143: syntax error : missing  ;  before  < 
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding  ; 
error C2065:  device  : undeclared identifier

这样,我就能够利用这一方法将通信点从职能中退回,并确保它们在离开电线员范围时予以删除?

最佳回答

通常有两种处理COM智能点的方法,我建议:

(1) 你可以进口适当的类型的图书馆,该图书馆将自动产生基于_com_ptr_t的智能点类型。

2) 您可以使用CComPtr模板,在通过自动添加/转录电话对资源管理进行照顾的智能点中总结你的原材料,但并未给予你其他许多东西。

由于我略微 la笑,而且通常我不会忘记由<条码>第进口<>/代码>产生的包装自动产生的隐含间接费用,我通常使用1。 采用这一方法的一个巨大好处是,<代码>#import机制还产生功能总结,使COM功能更像正常功能,有适当的回归类型,并翻译<代码>HRESULT至_com_error的例外情况物体。 IMHO倾向于改进C++COM代码的控制流动。

问题回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签