c++中执行exe

//写出obj
	ofstream writeObj;
	writeObj.open(folderfilepath+"writeobj.obj");
		for (int k = 0; k < m_vVert.size(); k++){
			ZVert vtemp = m_vVert[k];
			double vix = vtemp.Co3d().x;
			double viy = vtemp.Co3d().y;
			double viz = vtemp.Co3d().z;

			ostringstream oss;
			oss << vix;
			string strx = oss.str();

			ostringstream oss1;
			oss1 << viy;
			string stry = oss1.str();

			ostringstream oss2;
			oss2 << viz;
			string strz = oss2.str();
			//endl换行无效,改为\r\n
			writeObj << "v " << strx << " " << stry << " " << strz << "\r\n";
		}
		for (int ci = 0; ci < m_vFace.size(); ci++){
			ZFace &fa = m_vFace[ci];
			int indx1 = fa.GetIndex(0);
			int indx2 = fa.GetIndex(1);
			int indx3 = fa.GetIndex(2);
			//obj face id start from 1 not 0

			writeObj << "f " << indx1 + 1 << "// " << indx2 + 1 << "// " << indx3 + 1 << "// " <<"\r\n";
		}
		writeObj.close();
	//调用exe
	//system("HierarSpherePara.exe ");
	string file_path = folderfilepath+"writeobj.obj";
	string txt_out_path = folderfilepath+"writeobj.obj.txt";
	string txt_out_path2 = folderfilepath+"result_record.txt";
 
	string exefilepath = folderfilepath+"HierarSpherePara.exe";
	LPCSTR exestr = exefilepath.c_str();
	string exefilepath1 = folderfilepath;
	LPCSTR exestr1 = exefilepath1.c_str();
	HINSTANCE hd ;
    hd = ShellExecute(NULL,"open",exestr, "writeobj.obj 1 20 ", exestr1, SW_SHOW);

	//读入参数化好 的结果文件
	string out_file_path = folderfilepath+"writeobj.obj_op.obj";  
	//不管执行的程序是否成功运行,运行的时间是长是短,ShellExecute函数都会立即返回
	if (( long )hd > 32)
    {
		//确保输出了obj文件
		while(1){
			if(LoadMeshfromObj(out_file_path.c_str())){
				//AfxMessageBox("读取参数化后的obj成功!");
				break;
			}
			
		}
	
	//删除文件
		//BOOL d,d1,d2,d3 = false;
		
		while(1){ //删除导出的obj
			if(DeleteFile(file_path.c_str())){
			break;
			}
		}
		while(1){ //删除新生成的obj
			if(DeleteFile(out_file_path.c_str())){
			break;
			}
		}

	return true;
	}
	else{
	
	AfxMessageBox("exe执行失败!");
	return false;
	}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值