Wolfgang Chien's Homepage | Delphi學習筆記 - 問答篇 |
謝謝 wcwang@mail.systex.com.tw (Wen-Ching Wang) 來信問到: CreateProcess() 在執行 Delphi 產生的 EXE 檔時, 會造成 GP Fail 的錯誤情況.
經過檢查後, 我發覺是我對該函數的用法了解得不過明白所致, CreateProcess 呼叫前需填入 TStartInfo 的內容, 所以, 在「如何執行外部程式」中所列的程式至少應該要如下列的寫法:
procedure TForm1.Button1Click(Sender: TObject); var sCommandLine: string; bCreateProcess: boolean; lpStartupInfo: TStartupInfo; lpProcessInformation: TProcessInformation; begin sCommandLine := 'D:\TEMP\TEST.EXE'; // 填入 StartupInfo FillChar(lpStartupInfo, Sizeof(TStartupInfo), #0); lpStartupInfo.cb := Sizeof(TStartupInfo); lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW; lpStartupInfo.wShowWindow := SW_NORMAL; bCreateProcess := CreateProcess(nil, PChar(sCommandLine), nil, nil, True, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, lpStartupInfo, lpProcessInformation); end;
首頁 | 學習筆記 | 主題公園 | 軟體下載 | 關於本站 | 討論信群 | 相約下次 |