我想让我的其他C++程序从另一个文件运行,所以我使用的是shell执行。穆代码:在shellexecute中传递文件路径作为参数
#pragma comment(lib,"shell32.lib")
#include "windows.h"
#include<Shellapi.h>
#include<stdio.h>
#include<iostream>
using namespace std;
class spwan{
public:
//char szPath[] = "";
void run(char path[]);
};
void spwan::run(char szPath[]){
HINSTANCE ShellExecute(HWND, "open", szPath,"","",SW_SHOW);
cout<<"program executed";
}
int main()
{
spwan s;
s.run("path to the file");
}
,但我有一样的问题有望类型说明符与“开放”,我不能够确定使用szPath的路径。 Anyhelp。如果你有任何问题,请联系我们,我们会尽快为你解答。作为语法错误:'string'
当我给这样的路径: - C:\ Users \ saira \ Documents \ Visual Studio 2010 \ Projects \ phase_1_solver \ Debug \ phase_1_solver.exe它给出错误,如:警告C4129: “S”:无法识别的字符转义序列警告C4129:“d”:无法识别的字符转义序列
请告诉我们什么是错的。编译器错误?运行时失败?并提供确切的信息。此外,它拼写'spawn'。无需在此处传递窗口句柄。通过'0'。也不需要传递动词,通过'NULL'。其他两个参数也通过'NULL'而不是''“'。 – 2013-03-11 15:38:55
这真的归结为如何正确调用一个函数,如果你不能这样做,我强烈建议不要进入Windows API。 – chris 2013-03-11 15:39:11
我想知道的主要事情是如何使用路径作为参数。 – networks 2013-03-11 15:42:07