魔法老师完整版百度云:c语言调用exe文件

来源:百度文库 编辑:高考问答 时间:2024/05/10 20:00:04
如路径下d:\yun.exe
如果可以用..\yun.exe相对路径更好
谢谢 回答者:¤幽幽幻客¤ - 秀才 二级 的勇敢发言。
可是能不能给个c的代码
buaa_sheng - 魔法师 五级 谢谢你 可是编译不过去阿。是不是C#的代码

#include "stdafx.h"
#include "tttt.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{

UINT nReturnValue = WinExec("..\\ReadFromFile.exe",SW_SHOW);
if(nReturnValue == 0){
AfxMessageBox("Out of Memory!",MB_OK);
return 1;
}
if(nReturnValue == ERROR_BAD_FORMAT){
AfxMessageBox("Not a Win32 Application!",MB_OK);
return 1;
}
if(nReturnValue == ERROR_FILE_NOT_FOUND){
AfxMessageBox("Not Found the Specific File!",MB_OK);
return 1;
}
if(nReturnValue == ERROR_PATH_NOT_FOUND){
AfxMessageBox("Not Found the Specific Path!",MB_OK);
return 1;
}

return 0;

}

return nRetCode;
}

dir/w 输入你想调用的EXE文件名