gpt4 book ai didi

c++ - 如何在QT Creator中检查ShellExecute命令返回(HINSTANCE)代码

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:32:03 26 4
gpt4 key购买 nike

我正在使用 Shell 命令启动一个进程。我的开发环境是 C++/QT Creator/QT Libraries 和 Windows APIs。

如何处理 HINSTANCE 返回值? if (hInstance < 32) 代码抛出编译错误

    437: error: ISO C++ forbids comparison between pointer and integer


HINSTANCE hInstance = ShellExecute(0, QString("open").toStdWString().c_str(), Path.toStdWString().c_str(), 0, 0, SW_SHOWNORMAL);
if (hInstance < 32)
qDebug() << "Error";

最佳答案

如果有人仍在为此苦苦挣扎,这里有一个避免警告的解决方案:

int retValue = static_cast<int>(reinterpret_cast<uintptr_t>(ShellExecute(<etc>)));

参见 When is uintptr_t preferred over intptr_t?有关 uintptr_t 的更多评论

关于c++ - 如何在QT Creator中检查ShellExecute命令返回(HINSTANCE)代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10905648/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com