使用winrt :: com_ptr< ID3D11Device1>与D3D11CreateDevice()? [英] Using winrt::com_ptr<ID3D11Device1> with D3D11CreateDevice()?

查看:126
本文介绍了使用winrt :: com_ptr< ID3D11Device1>与D3D11CreateDevice()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究 DirectXTK示例项目的代码并尝试在新项目中实施它.似乎Microsoft 建议在Windows中使用WinRT不过是新项目,所以我决定尝试将 WRL :: ComPtr 的实例切换为 winrt :: com_ptr 的实例.不过,我被困在尝试在项目 Game 类中的 ID3D11Device1 D3D11CreateDevice() ID3DDevice 之间移动>.

以下是示例代码,为简单起见,对其进行了略微抽象:

  ComPtr< ID3D11Device1>global_device;无效CreateDevice(){...ComPtr< ID3D11Device>local_device;ThrowIfFailed(D3D11CreateDevice(... local_device.ReleaseAndGetAddressOf()...));ThrowIfFailed(local_device.As(& global_device));} 

这是我在WinRT中的近似值:

  com_ptr< ID3D11Device1>global_device;无效createDevice(){...com_ptr< ID3D11Device>local_device;check_hresult(D3D11CreateDevice(... local_device.put()...));global_device = local_device.as< ID3D11Device1>();} 

但是,每次运行它时,都会出现以下错误:

 错误C2664'HRESULT IUnknown :: QueryInterface(const IID&,void **)':无法将参数1从'const winrt :: guid'转换为'const IID&'HelloDX11.\ x64 \ Debug \ Generated Files \ winrt \ base.h 1955消息没有可用的用户定义的转换运算符可以执行此转换,或者该运算符不能称为HelloDX11.\ x64 \ Debug \ Generated Files \ winrt \ base.h 1955消息原因:无法从'const winrt :: guid'转换为'const IID'HelloDX11.\ x64 \ Debug \ Generated Files \ winrt \ base.h 1955消息请参见对功能模板实例化'winrt :: com_ptr< ID3D11Device1>winrt :: com_ptr< ID3D11Device> :: as< ID3D11Device1>(void)const'正在编译HelloDX11.\ game.cpp 47消息请参见对功能模板实例化'winrt :: com_ptr< ID3D11Device1>winrt :: impl :: as< To,ID3D11Device>(From *)'正在被编译和[到= ID3D11Device1,发件人= ID3D11Device] HelloDX11.\ x64 \ Debug \ Generated Files \ winrt \ base.h 2377 

我已经查看了 WRL :: ComPtr.As()的文档解决方案

每个 IInspectable 的评论:

" winrt :: guid 会转换为GUID,只要在包含任何C ++/WinRT标头之前就包含Unknwn.h."请参阅:DirectXTK example project and trying to implement it in a new project. It seems like Microsoft recommends using WinRT in new projects, though, so I decided I would try to switch instances of WRL::ComPtr to winrt::com_ptr. I'm stuck, though, trying to move between ID3D11Device1 in the project's Game class and ID3DDevice in D3D11CreateDevice().

Here's the example code, slightly abstracted for simplicity's sake:

ComPtr<ID3D11Device1> global_device;

void CreateDevice()
{
    ...

    ComPtr<ID3D11Device> local_device;
    ThrowIfFailed(D3D11CreateDevice( ... local_device.ReleaseAndGetAddressOf() ... ));
    ThrowIfFailed(local_device.As(&global_device));
}

And here's my approximation of it with WinRT:

com_ptr<ID3D11Device1> global_device;

void createDevice()
{
    ...

    com_ptr<ID3D11Device> local_device;
    check_hresult(D3D11CreateDevice( ... local_device.put() ... ));
    global_device = local_device.as<ID3D11Device1>();
}

Every time I run it, though, I get these errors:

Error   C2664    'HRESULT IUnknown::QueryInterface(const IID &,void **)': cannot convert argument 1 from 'const winrt::guid' to 'const IID &'   HelloDX11   .\x64\Debug\Generated Files\winrt\base.h    1955    
Message      No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called   HelloDX11   .\x64\Debug\Generated Files\winrt\base.h    1955    
Message      Reason: cannot convert from 'const winrt::guid' to 'const IID' HelloDX11   .\x64\Debug\Generated Files\winrt\base.h    1955    
Message      see reference to function template instantiation 'winrt::com_ptr<ID3D11Device1> winrt::com_ptr<ID3D11Device>::as<ID3D11Device1>(void) const' being compiled    HelloDX11   .\game.cpp  47  
Message      see reference to function template instantiation 'winrt::com_ptr<ID3D11Device1> winrt::impl::as<To,ID3D11Device>(From *)' being compiled
        with
        [
            To=ID3D11Device1,
            From=ID3D11Device
        ]   HelloDX11   .\x64\Debug\Generated Files\winrt\base.h    2377    

I've gone over the docs for WRL::ComPtr.As() here, the docs for winrt::com_ptr.as() here, and the "conversion" example here about as many times as I can stand at this point. What am I missing?

解决方案

Answer per IInspectable's comment:

"winrt::guid converts to GUID, as long as you include Unknwn.h before you include any C++/WinRT headers." See: https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/news#news-and-changes-in-windows-sdk-version-100177630-windows-10-version-1809

这篇关于使用winrt :: com_ptr&lt; ID3D11Device1&gt;与D3D11CreateDevice()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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