在将ShellExecute返回值强制转换为int时,我们可以使用C++11中的reinterpret_cast代替C风格的强制转换。这将清除MSVC的警告并提供更好的代码可读性。
示例代码如下:
#include
int main()
{
// Executes "notepad.exe" and opens "test.txt"
HINSTANCE hInstance = ShellExecute(NULL, "open", "notepad.exe", "test.txt", NULL, SW_SHOWNORMAL);
if(reinterpret_cast(hInstance) <= 32)
{
// There was an error opening the file.
return -1;
}
return 0;
}