QueryInterface()在哪里 [英] Where is QueryInterface()

查看:98
本文介绍了QueryInterface()在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


   

在Kenny Kerr的文章
图形和动画
他的代码有很多问题。



[1] 他使用宏或模板'check()' ,这是哪里,我没有?

    check_hresult()//我改用它,这可以吗?
b
$ b [2] 他用另一个东西'set()',如在set(direct3dDevice)中,我也没有这个。

    & direct3dDevice,//我用它来代替,这样可以吗?
b
$ b [3] 在以下代码行中,我必须排除括号以使其编译,这样可以吗?

  &NBSP; ComPtr< IDXGIDevice3> dxgiDevice = direct3dDevice.As< IDXGIDevice3>(); //将无法编译

  &NBSP; dxgiDevice = direct3dDevice.As< IDXGIDevice3> ;; //我正在使用它。



[4] 与set(..)类似,他也使用get(.. )如... ..
    check(D2D1CreateDevice( get( dxgiDevice ,properties,set(direct2dDevice))); //没有得到(..)


    //我使用.Get()附加到设备对象上。

    winrt :: check_hresult(D2D1CreateDevice(dxgiDevice.Get(),properties,& direct2dDevice));



[5] 最后,最重要的是,因为我找不到任何类似于替代品的东西。 QueryInterface()不是Compositor的已知函数。
$
    check(compositor-> QueryInterface(set(compositorInterop)));



解决方案

1)这可能在任何地方都不存在,而是用来表示你应该检查结果。样本通常使用此方法,例如

Direct2D快速入门
使用DX :: ThrowIfFailed,这在任何地方都不存在。这只是一些神秘的功能,很大程度上暗示你应该检查返回并立即处理错误情况。所以check_hresult是可以的,但要注意
这将抛出一个C ++异常。


2,4)set和get函数是一种通用的说法"你应该写入此指针"和"你应该从这个指针读取"。如果你使用原始指针,那么这将是指针的地址,只是原始指针:

 ID2D1Device * direct2dDevice; 
ABI :: Windows :: UI :: Composition :: ICompositionGraphicsDevice * device;

compositorInterop-> CreateGraphicsDevice(direct2dDevice / * get * /,& device / * set * /)

如果您使用的是Microsoft: :WRL :: ComPtr,这是Get和GetAddressOf:

 Microsoft :: WRL :: ComPtr< ID2D1Device> direct2dDevice; 
Microsoft :: WRL :: ComPtr< ABI :: Windows :: UI :: Composition :: ICompositionGraphicsDevice>设备;

compositorInterop-> CreateGraphicsDevice(direct2dDevice.Get()/ * get * /,device.GetAddressOf()/ * set * /);

如果你正在使用任何其他智能指针类型,那么你将不得不寻找沿着这一行的东西。


3)那实际上是为你编译的?对我来说,它给出了编译器错误,因为direct3dDevice.As< IDXGIDevice3>是一个成员函数,并且您正在尝试创建一个指向该成员的指针。


使用As的方式为Microsoft :: WRL :: ComPtr:

 direct3dDevice.As(& dxgiDevice); 

这将进行转换并将新接口放入dxgiDevice。


5)如果您使用的是C ++ / WinRT,那么您应该从SoftwareBitmap问题中注意到,它完全隐藏了这些对象的COM特性,并使用as成员函数进行查询。 / p>

例如:

 ComPtr< ABI :: Windows :: UI :: Composition :: ICompositorInterop> compositorInterop = compositor.as< ABI :: Windows :: UI :: Composition :: ICompositorInterop>()。get(); 

最后的.get()是需要因为返回它自己的智能指针类型,你需要把它从那里拿出来。


Hi,

   

In Kenny Kerr's article Graphics and Animation there are a number of issues with his code.

[1] he uses a macro or template 'check()', where is this, I don't have it?
    check_hresult() // I use this instead, is this OK?

[2] He uses another thing 'set()', as in set(direct3dDevice), I don't have this either.
    &direct3dDevice, // I use this instead, is this OK?

[3] In the following line of code I had to exclude the brackets to make it compile, Is this OK?
    ComPtr<IDXGIDevice3> dxgiDevice = direct3dDevice.As<IDXGIDevice3>(); // won't compile
    dxgiDevice = direct3dDevice.As<IDXGIDevice3>; // I'm using this instead.

[4] Similar to set(..), he also uses get(..) as in ..
    check(D2D1CreateDevice(get(dxgiDevice), properties, set(direct2dDevice))); // no get(..)
    // I use .Get() appended to the device object instead ..
    winrt::check_hresult(D2D1CreateDevice(dxgiDevice.Get(), properties, &direct2dDevice));

[5] And finally, and most importantly, because I can't find anything that even resembles an alternative. QueryInterface() isn't a known function of Compositor ..
    check(compositor->QueryInterface(set(compositorInterop)));

解决方案

1) This may not exist anywhere, but instead be used as a way to say that you should just check the results. The samples usually use this, like the Direct2D quickstart uses DX::ThrowIfFailed, and this doesn't exist anywhere. It is just some mythical function that heavily implies that you should check the return and deal with the error condition immediately. So check_hresult is okay, but be aware that this will throw a C++ exception.

2,4) The set and get functions are some generic way of saying "you should write to this pointer" and "you should read from this pointer". If you are using raw pointers then this would be address of the pointer and just the raw pointer:

ID2D1Device *direct2dDevice;
ABI::Windows::UI::Composition::ICompositionGraphicsDevice *device;

compositorInterop->CreateGraphicsDevice(direct2dDevice /*get*/, &device /*set*/)

If you are using Microsoft::WRL::ComPtr, this is Get and GetAddressOf:

Microsoft::WRL::ComPtr<ID2D1Device> direct2dDevice;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionGraphicsDevice> device;

compositorInterop->CreateGraphicsDevice(direct2dDevice.Get() /*get*/, device.GetAddressOf() /*set*/);

If you are using any other smart pointer type, then you will have to look for things along this line.

3) That actually compiles for you? For me it gives a compiler error because direct3dDevice.As<IDXGIDevice3> is a member function, and you are trying to create a pointer to member there.

The way to use As for Microsoft::WRL::ComPtr is:

direct3dDevice.As(&dxgiDevice);

this will do the conversion and place the new interface into dxgiDevice.

5) If you are using C++/WinRT, then as you should have noticed from the SoftwareBitmap question, it completely hides the COM nature of these objects, and the as member function is used to do the query.

So for example:

ComPtr<ABI::Windows::UI::Composition::ICompositorInterop> compositorInterop = compositor.as<ABI::Windows::UI::Composition::ICompositorInterop>().get();

the .get() at the end is needed because as returns its own smart pointer type, and you need to get it out of there.


这篇关于QueryInterface()在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆