gpt4 book ai didi

c++ - TCHAR 数组到串联 LPCSTR

转载 作者:行者123 更新时间:2023-11-27 23:45:25 25 4
gpt4 key购买 nike

我正在读取一个 ini 文件,然后想执行一个外部程序(VBS 文件)。但是我在字符串类型方面遇到了问题。

这是我的代码。

LPCTSTR path = _T(".\\my.ini");
TCHAR fileName[500];
int b = GetPrivateProfileString(_T("Paths"), _T("filename"), _T(""), fileName, 500, path);
// fileName = myscript.vbs
// I need to execute "wscript myscript.vbs arg1"
// Execute script file. Doesnt work.
WinExec("wscript " + fileName + " arg1", MINIMZIED);
// OR. Doesnt work.
system("wscript " + fileName + " arg1");

这行不通。 WinExec 想要一个 LPCSTR 但我在 TCHAR[] 中有 fileName 并且想与其他一些字符串连接。

如何正确转换或连接它?

最佳答案

来自WinExec() documentation :

This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.

这是CreateProcessW()在你的情况下。

或者,您可以使用 _wsystem()

关于c++ - TCHAR 数组到串联 LPCSTR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51093035/

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