我正在尝试用C ++编写程序来启动可执行文件。当我尝试运行该程序时,没有任何反应。但是,当我尝试在同一目录上运行该程序并驱动exe进入时,它确实可以工作。
这是代码:
else if (result1 == 0) {
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
{
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
si.cb = sizeof(si);
CreateProcess(L"D:\\Games\\Origin Games\\Command and Conquer Red Alert\\RA95Launcher.exe", NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
当我这样做时:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
{
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
si.cb = sizeof(si);
CreateProcess(L"D:\\Games\\Origin Games\\Command and Conquer Red Alert\\RA95Launcher.exe", NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, "D:\\Games\\Origin Games\\Command and Conquer Red Alert\\", &si, &pi);
我得到了错误:
“ const char *”类型的参数与“ LPCWSTR”类型的参数不兼容
任何帮助将不胜感激。
答案 0 :(得分:0)
很可能应该将++
参数设置为exe所在的目录。
请参阅:CreateProcess
hour = int(input("Starting time (hours): "))
mins = int(input("Starting time (minutes): "))
dura = int(input("Event duration (minutes): "))
hour = hour +int((mins+dura)/60)
mins = (mins + dura)%60
while(hour/24>=1):
hour=hour-24
print(hour, ":", mins, sep='')
之类的可执行文件通常依赖于其他文件。通常,从lpCurrentDirectory
的角度来看,这些是由RA95Launcher.exe
引用的。
如果从exe所在的目录中启动该进程,则会自动使用正确的relative path
。如果启动器在其他位置运行,则需要指定启动器。
答案 1 :(得分:0)
我得到错误:类型为“ const char *”的参数与 类型为“ LPCWSTR”的参数
这意味着您正在尝试将不兼容的类型传递给函数。 LPCWSTR
是Windows.h
的{{1}} typedef(UTF-16字符串),但const wchar_t*
需要ANSI字符串(CreateProcess
)。您可以调用适当的函数,在这种情况下-LPCSTR
(函数名末尾的W表示它将UTF-16字符串作为参数),也可以通过删除前面的CreateProcessW
来使字符串成为ANSI。