Visual Studio
想通过这个警告告诉我什么?
根据 docs,当您向参数传递可能为空值时会出现此警告。
但是在调用这些函数之前我会使用
if (hwnd)
检查 null 。
if (hwnd) {
GetClientRect(hwnd, (LPRECT)&rMyRect);
ClientToScreen(hwnd, (LPPOINT)&rMyRect.left);
ClientToScreen(hwnd, (LPPOINT)&rMyRect.right);
}
您测试它的事实并不相关,编译器没有检测到该测试。 但是,您可以使用:
#pragma warning(suppress : 6387)
在前一行,这将阻止该消息(或使用 __Pragma(warning(suppress : 6387)),但我更喜欢 #pragma 形式。
这就是我如何仅针对受影响的代码块禁用警告 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。