visual-c++ - 代码分析警告 C26476 和初始化 TASKDIALOGCONFIG 结构
问题描述
本文有一个关于TASKDIALOGCONFIG
使用结构的深入教程。在该教程中,它指出:
以下代码创建了一个最小的任务对话框:
TASKDIALOGCONFIG config = { sizeof (TASKDIALOGCONFIG) };
在我的代码中,我有类似的东西:
TASKDIALOGCONFIG sConfig = { sizeof(TASKDIALOGCONFIG) };
那么,为什么代码分析会说:
警告C26476:表达式/符号
{0}
使用带有多个类型指针的裸联合“联合”:改用变体 (type.7)。
我们最近进行了一次讨论,提出了使用std::variant
. 但这种结构被定义为:
typedef struct _TASKDIALOGCONFIG
{
UINT cbSize;
HWND hwndParent; // incorrectly named, this is the owner window, not a parent.
HINSTANCE hInstance; // used for MAKEINTRESOURCE() strings
TASKDIALOG_FLAGS dwFlags; // TASKDIALOG_FLAGS (TDF_XXX) flags
TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons; // TASKDIALOG_COMMON_BUTTON (TDCBF_XXX) flags
PCWSTR pszWindowTitle; // string or MAKEINTRESOURCE()
union
{
HICON hMainIcon;
PCWSTR pszMainIcon;
} DUMMYUNIONNAME;
PCWSTR pszMainInstruction;
PCWSTR pszContent;
UINT cButtons;
const TASKDIALOG_BUTTON *pButtons;
int nDefaultButton;
UINT cRadioButtons;
const TASKDIALOG_BUTTON *pRadioButtons;
int nDefaultRadioButton;
PCWSTR pszVerificationText;
PCWSTR pszExpandedInformation;
PCWSTR pszExpandedControlText;
PCWSTR pszCollapsedControlText;
union
{
HICON hFooterIcon;
PCWSTR pszFooterIcon;
} DUMMYUNIONNAME2;
PCWSTR pszFooter;
PFTASKDIALOGCALLBACK pfCallback;
LONG_PTR lpCallbackData;
UINT cxWidth; // width of the Task Dialog's client area in DLU's. If 0, Task Dialog will calculate the ideal width.
} TASKDIALOGCONFIG;
那么我们如何绕过这个警告呢?
解决方案
推荐阅读
- java - 使用 Recusion for Android 的异常行为
- git - 我可以与同一个 git repo 中的其他子目录共享一个子目录吗?
- php - 添加 1 天至今的代码不起作用
- r - 如何从 h2o 回归中获得 VIF
- flex-lexer - flex lexer:在 yytext 更改后我应该更新哪个变量?
- influxdb - InfluxDB 模式设计 - 只需汇总数千个时间序列数据
- c# - 如何检查日期是否对 3 个整数有效?(方法返回布尔值)
- javascript - 如何修复'php跳过我的if语句'
- docker - 如何区分 Docker Toolbox 和 Docker for Mac/Windows?
- r - 如果包含在包中,Shinyjs 切换不起作用