如何调用外部exe文件?

老徐要好好学习 2006-01-04 04:37:42
如何调用外部的应用程序(exe 形式的带有参数的文件) ?
用什么函数??
总样加入参数??

在线等待.............
...全文
184 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我自己回答算了!
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21634002.html

1.ShellExecute:

- you only know if it started or failed
cFileName = "c:\Program Files\Winzip\Winzip32.Exe"
cAction = "open"
ShellExecute(0,cAction,cFileName,"","",SW_SHOWNORMAL)

If you want only to execute an EXE ShellExecute is best as CreateProcess is bit complicated..

HINSTANCE ShellExecute(HWND hwnd,
LPCTSTR Operation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);

hwnd=handle to window or can be NULL
Operation = "Open" // Open if you wan to execute EXE
lpFile= executable file name
lpParameters=command line parameters if any
lpDirectory=full path to directory where executable exists
nShowCmd=SW_SHOW // to show window
or = SW_HIDE //hide window

if you want to set full path to executable you can set it by assigning to lpDirectory.

e.g ShellExecute(NULL,"Open","NOTEPAD.EXE",NULL,"C:\Windows",SW_SHOW)


2.CreateProcess :you get information about the runing process (you can monitor its existance, find the HWND of the main window for SendMessage ....), in other words rather more information

here is a CreateProcess example:

STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
BOOL ProgRunning = false;
DWORD ExitCode = 0L;
CString Program = "Your path";

SecureZeroMemory(&StartupInfo, sizeof(STARTUPINFO));
SecureZeroMemory(&ProcessInfo, sizeof(PROCESS_INFORMATION));

StartupInfo.cb = sizeof(STARTUPINFO);

ProgRunning = CreateProcess(NULL, Program.GetBuffer(Program.GetLength()),
NULL, NULL,
0, 0,
NULL, NULL,
&StartupInfo, &ProcessInfo);
if(!ProgRunning)
return FALSE;

do
{
ProgRunning = GetExitCodeProcess(ProcessInfo.hProcess, &ExitCode);
if(!ProgRunning)
return FALSE;
}while(ExitCode == STILL_ACTIVE);
ouyh12345 2006-01-04
  • 打赏
  • 举报
回复
ShellExcuteEx
HelloIvan2005 2006-01-04
  • 打赏
  • 举报
回复
system("the path of the exe you want to call")
  • 打赏
  • 举报
回复
总么不能给分了??

我就是给10分系统也提示我给多了??


是不是我的问题太白吃了,连机器都觉得不值得一提呀?

:( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :(

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧