windows _com_error,comdef. h-捕获D3 D12中的异常

fhg3lkii  于 2022-11-18  发布在  Windows
关注(0)|答案(1)|浏览(159)

我在图形渲染期间尝试从着色器中的上载堆读取数据后遇到了一个奇怪的_com_error异常。
在查找_com_error之后,似乎需要像捕获异常一样捕获它:

try
{
    // attempt to present the scene
    System.SwapChain->Present( App.Video.Option.Set(videoSet::VERTICAL_SYNC) ? 1 : 0 );
}
catch(_com_error &x)
{
    app_error( x.ErrorMessage() );
}

然而,要使用_com_error,我显然需要包含comdef.h,而当我包含comdef.h时,我得到了很多警告和错误。第一组警告/错误似乎来自一个次要包含,它显然包含在comdef. h中,C:\Windows Kits\10\Include\10.0.22621.0\um\ole2.h。我尝试的第一件事是 Package 我的包含(我使用的是Visual Studio 2022):

#pragma warning(push, 0)
#include <comdef.h>
#pragma warning(pop)

然而,这似乎根本不起作用,即使我尝试在项目中包含的其他文件都起作用。即使这样,我仍然收到警告,这些警告被视为错误。以下是其中的一些警告:

1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(92,41): error C2220: the following warning is treated as an error
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(92,41): warning C4229: anachronism used: modifiers on data are ignored
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(92,41): error C2491: 'OleBuildVersion': definition of dllimport data not allowed
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(92,36): error C2065: 'VOID': undeclared identifier
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(94,50): warning C4229: anachronism used: modifiers on data are ignored
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(94,50): error C2491: 'WriteFmtUserTypeStg': definition of dllimport data not allowed
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(94,47): error C2065: 'IN': undeclared identifier
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(94,50): error C2146: syntax error: missing ')' before identifier 'LPSTORAGE'
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(95,34): warning C4229: anachronism used: modifiers on data are ignored
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(95,34): error C2491: 'ReadFmtUserTypeStg': definition of dllimport data not allowed
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(95,31): error C2065: 'IN': undeclared identifier
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(95,34): error C2146: syntax error: missing ')' before identifier 'LPSTORAGE'
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(100,43): warning C4229: anachronism used: modifiers on data are ignored
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(100,43): error C2491: 'OleInitialize': definition of dllimport data not allowed
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(100,40): error C2065: 'IN': undeclared identifier
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(100,43): error C2146: syntax error: missing ')' before identifier 'LPVOID'
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(107,36): warning C4229: anachronism used: modifiers on data are ignored
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(107,36): error C2491: 'OleQueryLinkFromData': definition of dllimport data not allowed
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(107,33): error C2065: 'IN': undeclared identifier
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(107,36): error C2146: syntax error: missing ')' before identifier 'LPDATAOBJECT'
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(108,38): warning C4229: anachronism used: modifiers on data are ignored
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(108,38): error C2491: 'OleQueryCreateFromData': definition of dllimport data not allowed
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(108,35): error C2065: 'IN': undeclared identifier
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(108,38): error C2146: syntax error: missing ')' before identifier 'LPDATAOBJECT'
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(113,25): warning C4229: anachronism used: modifiers on data are ignored
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(113,25): error C2491: 'OleCreate': definition of dllimport data not allowed
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(113,22): error C2065: 'IN': undeclared identifier
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(113,25): error C2059: syntax error: 'const'
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(118,27): warning C4229: anachronism used: modifiers on data are ignored
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(118,27): error C2491: 'OleCreateEx': definition of dllimport data not allowed
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(118,24): error C2065: 'IN': undeclared identifier
1>C:\Windows Kits\10\Include\10.0.22621.0\um\Ole2.h(118,27): error C2059: syntax error: 'const'

这是否与我正在使用的Windows工具包有关?我记得几年前尝试过这样做,但遇到了同样的问题,最终放弃了捕捉异常的尝试。
有人能指出我在这种情况下的无知吗?任何指导都将非常感激。

wlsrxk51

wlsrxk511#

该问题是由另一个包含使用#undef VOID的标头沿着删除Windows使用的其他几个定义引起的。
我不得不在include上面包含comdef.h来使它工作,但这样做解决了我的问题。如果其他人遇到类似的错误,请确保您在其他窗口头文件沿着包含comdef.h,以防某些头文件决定轰炸Microsoft #define 'namespace'。

相关问题