我正在尝试编写一个非常简单的程序来替换现有的可执行文件。它应该稍微调整它的参数并使用新参数执行原始程序。它应该由第三方库自动且静默地调用。
它运行良好,但它会弹出一个控制台窗口来显示调用程序的输出。我需要那个控制台窗口不存在。我不关心程序的输出。
我最初的尝试是设置为控制台应用程序,所以我想我可以通过编写一个新的 Windows GUI 应用程序来解决这个问题。但它仍然会弹出控制台。我假设原始命令被标记为控制台应用程序,因此 Windows 会自动为其提供一个控制台窗口以在其中运行。我还尝试用对 system() 的调用替换我对 _exec() 的原始调用,以防万一。没有帮助。
有谁知道我怎样才能让这个控制台窗口消失?
这是我的代码:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
char* lpCmdLine,
int nCmdShow)
{
char *argString, *executable;
// argString and executable are retrieved here
std::vector< std::string > newArgs;
// newArgs gets set up with the intended arguments here
char const ** newArgsP = new char const*[newArgs.size() + 1];
for (unsigned int i = 0; i < newArgs.size(); ++i)
{
newArgsP[i] = newArgs[i].c_str();
}
newArgsP[newArgs.size()] = NULL;
int rv = _execv(executable, newArgsP);
if (rv)
{
return -1;
}
}