VC 呼叫外部程式

2021-06-01 13:04:32 字數 1100 閱讀 3369

有三種sdk函式可以呼叫,分別是:

winexec, shellexecute,createprocess

其中以winexec最為簡單,主要是呼叫windows程式.

shellexecute比winexec靈活一些,主要是呼叫dos程式。

createprocess最為複雜但是使用最靈活。

1.winexec 有兩個引數,前乙個指定路徑,後乙個指定顯示方式。這個方式有個缺點,不能指定工作目錄。

2.shellexecute 可以指定工作目錄,並且還可以尋找檔案的關聯直接開啟不用載入與檔案關聯的應用程式,shellexecute還可以開啟網頁,啟動相應的郵件關聯傳送郵件等等。

函式原型如下:

hinstance shellexecute(

hwnd hwnd, 

//父視窗控制代碼

lpctstr lpoperation, 

//操作, 開啟方式"edit","explore","open","find","print","null"

lpctstr lpfile, 

//檔名,前面可加路徑

lpctstr lpparameters, 

//引數

lpctstr lpdirectory, 

//預設資料夾

int nshowcmd 

//顯示方式

);例如:

啟動乙個程式直到它執行結束

shellexecuteinfo shexecinfo = ;

shexecinfo.cbsize = sizeof(shellexecuteinfo);

shexecinfo.fmask = see_mask_nocloseprocess;

shexecinfo.hwnd = null;

shexecinfo.lpverb = null;

shexecinfo.lpfile = "c:\\myprogram.exe"; 

shexecinfo.lpparameters = ""; 

shellexecuteex(&shexecinfo);

waitforsingleobject(shexecinfo.hprocess,infinite);

VC 呼叫外部程式介面

1 system 函式名 system 功 能 發出乙個dos命令 用 法 int system char command 備 注 system函式已經被收錄在標準c庫中,可以直接呼叫 返回值 1 出現錯誤 0 呼叫成功但是沒有出現子程序 0 成功退出的子程序的id 樣例 system d game...

VC 呼叫外部可執行程式

方法一 winexec notepad.exe,sw show 方法二 shellexecute null,open notepad.exe null,null,sw showmaximized 方法三 startupinfo si zeromemory si,sizeof startupinfo ...

VC 呼叫外部可執行程式

方法一 winexec notepad.exe,sw show 方法二 shellexecute null,open notepad.exe null,null,sw showmaximized 方法三 startupinfo si zeromemory si,sizeof startupinfo ...