警告 C6387 Visual Studio

问题描述 投票:0回答:3

Visual Studio
想通过这个警告告诉我什么?

根据 docs,当您向参数传递可能为空值时会出现此警告。

但是在调用这些函数之前我会使用

if (hwnd)
检查 null 。

if (hwnd) {
    GetClientRect(hwnd, (LPRECT)&rMyRect);
    ClientToScreen(hwnd, (LPPOINT)&rMyRect.left);
    ClientToScreen(hwnd, (LPPOINT)&rMyRect.right);
}
c++ visual-studio winapi warnings
3个回答
2
投票

您测试它的事实并不相关,编译器没有检测到该测试。 但是,您可以使用:

#pragma warning(suppress : 6387)

在前一行,这将阻止该消息(或使用 __Pragma(warning(suppress : 6387)),但我更喜欢 #pragma 形式。


1
投票

由于 IntelliSense 取消了您想要摆脱的内容(不是编译时警告),看起来没有特定的选项可以强制 IntelliSense 忽略该警告。您可以从 Visual Studio 窗口中的 Tools->Options->Text Editor->C/C++->Advanced 下整体禁用它,查看右侧的“代码”部分分析”;在此部分下,将“禁用 C++ 代码分析体验”设置为 True。

Tools->选项->文本编辑器->C/C++->*高级


1
投票

这就是我如何仅针对受影响的代码块禁用警告 6387;

#pragma warning( push )
#pragma warning( disable : 6387)
    GetClientRect(hwnd, (LPRECT)&rMyRect);
    ClientToScreen(hwnd, (LPPOINT)&rMyRect.left);
    ClientToScreen(hwnd, (LPPOINT)&rMyRect.right);
#pragma warning( pop )

感谢 -ScienceDiscover 指出我的错误,并且 NULL 实际上被定义为 0。

© www.soinside.com 2019 - 2024. All rights reserved.