Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ DirectX 12和C++;CLI:无法使用IID_PPV_参数_C++_Pointers_Command Line Interface_Directx - Fatal编程技术网

C++ DirectX 12和C++;CLI:无法使用IID_PPV_参数

C++ DirectX 12和C++;CLI:无法使用IID_PPV_参数,c++,pointers,command-line-interface,directx,C++,Pointers,Command Line Interface,Directx,对于给定的函数,如下所示: ID3D12Device* d3d12Device; D3D12CreateDevice(adapter, featureLevel, __uuidof(ID3D12Device), (void**)&d3d12Device); HRESULT D3D12创建设备( IUnknown*pAdapter, D3D\U特性级最低特性级, 雷菲德·里德, 无效设备 ); 使用C++的本地C++方式是: ID3D12Device* d3d12Device; D3

对于给定的函数,如下所示:

ID3D12Device* d3d12Device; 
D3D12CreateDevice(adapter, featureLevel, __uuidof(ID3D12Device), (void**)&d3d12Device);
HRESULT D3D12创建设备( IUnknown*pAdapter, D3D\U特性级最低特性级, 雷菲德·里德, 无效设备 );

使用C++的本地C++方式是:

ID3D12Device* d3d12Device; 
D3D12CreateDevice(adapter, featureLevel, IID_PPV_ARGS(&d3d12Device));
问题是我不能在a/CLI项目中使用IID_PPV_参数,因为托管代码中存在某种不可访问的宏

所以我尝试用DirectX 11和C++ CLI做的事情,如下:

ID3D12Device* d3d12Device; 
D3D12CreateDevice(adapter, featureLevel, __uuidof(ID3D12Device), (void**)&d3d12Device);
它不会产生任何编译器错误,但DX对象创建总是失败。。它曾与DX 11一起使用,但与DX12一起不再使用

有人能告诉我,在C++ CLI下如何初始化DX12对象?< /P> 非常感谢

编辑1

D3D12CreateDevice使用以下语法工作(我做错了什么):

但我无法获得CreateCommandQueue的正确语法

HRESULT CreateCommandQueue(常量D3D12_命令_队列_描述*pDesc,
REFIID riid,无效**ppCommandQueue)

此语法给出了一个强制转换错误:

_d3d12Device->CreateCommandQueue(&queueDesc, IID_ID3D12CommandQueue, (void**)&_commandQueue)

C2440“类型转换”:无法将“cli::interior_ptr”转换为“void**”

好的,我找到了方法,如果可以帮助其他人,我将在这里发布示例

首先,别像我一样傻,别忘了锁定本机对象的指针,否则GC会处理它们,调试会越来越困难:)

DX 12中的传统资源创建:

pin_ptr<ID3D12CommandQueue*> pCmdQueue = &_commandQueue;
_d3d12Device->CreateCommandQueue(&queueDesc, __uuidof(**(&_commandQueue)), (void**)pCmdQueue);
pin_ptr<ID3D12DebugDevice1*> pDeviceDebug = &_d3d12DeviceDebug;
_d3d12Device->QueryInterface<ID3D12DebugDevice1>(pDeviceDebug);
pin_ptr pCmdQueue=&u commandQueue;
_d3d12Device->CreateCommandQueue(&queueDesc,uuuIdof(**(&uCommandQueue)),(void**)pCmdQueue);
DX 12中的查询接口:

pin_ptr<ID3D12CommandQueue*> pCmdQueue = &_commandQueue;
_d3d12Device->CreateCommandQueue(&queueDesc, __uuidof(**(&_commandQueue)), (void**)pCmdQueue);
pin_ptr<ID3D12DebugDevice1*> pDeviceDebug = &_d3d12DeviceDebug;
_d3d12Device->QueryInterface<ID3D12DebugDevice1>(pDeviceDebug);
pin_ptr pDeviceDebug=&d3d12evicedebug;
_D3D12设备->查询接口(pDeviceDebug);

如果您没有得到有效的
d3d12Device
指针,您应该检查
D3D12CreateDevice
调用返回的值,另一个选项是启用调试层并查看调试输出。您需要检查
D3D12CreateDevice
的返回值以确定返回的指针是否有效(不是其他方式!)。也没有必要使用非标准的
\uuuuuuidof
运算符,您可以直接提供值,例如
IID\uid3d12device
。我不知道IID****谢谢。我用D3D12CreateDevice使用了错误的示例,因为它实际上使用了我的第二个语法。我可能在其他地方遇到了问题。但是对于像ID3D这样的东西12Device->CreateCommandQueue,我想不出我的编译器可以接受的语法。你不应该对DirectX COM对象使用
pin_ptr
,因为它们不是由GC管理的。请改用智能指针指向COM。如果我发布的所有内容都正确,这是一个问题吗?我总是在我的应用程序末尾做一个实时对象报告,以确保没有错误事情仍然有效。您应该将对象的释放委托给COM智能指针。而
pin_ptr
应该仅用于pin托管内存。感谢您的建议,我将查看它。