Comment attendre la fin d'un process lancé par ShellExecute ou ShellExecuteEx
Bonjour,
je dois lancer le Setup d'un programme via mon exécutable C++BuilderXE et attendre la fin de ce setup pour continuer.
J'ai pensé utiliser ShelleExecuteEx car je l'ai déjà fait en Vba. (sans tester la fin du code appelé mais en récupérant le hwnd pour tuer le process plus tard).
J'ai trouvé le code suivant en Delphi qui me parait adapté, mais étant plus que débuttant en C++(et Builder) je ne parviens pas à coder le protoype dans mon.h et la ligne de définition de ma fonction dans mon Form.
Voici le code delphi.
JE cite :
Le paramètre "voir" permet d'afficher ou non le programme lancé (c'est pratique), les autres paramètres se passe d'explication .
Déclaration
Code:
Function ExecuteWait(Programme, parametres :string;voir :Boolean):Boolean;
Implémentation :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| // Fonction permettant de lancer un programme externe et d'attendre la fin de celui-ci avant de continuer
Function TForm1.ExecuteWait(Programme, parametres :string;voir :Boolean):Boolean;
var ShExecInfo : TShellExecuteInfo;
begin
try
FillChar(ShExecInfo, SizeOf(ShExecInfo), 0);
with ShExecInfo do
begin
cbSize := SizeOf(ShExecInfo);
fMask := SEE_MASK_NOCLOSEPROCESS;
lpFile := PChar(Programme); { le nom du programme }
lpParameters := PChar(Parametres); { Les paramètres }
lpVerb := 'open';
if voir = True then nShow := SW_SHOW else nShow := SW_HIDE;
end;
if ShellExecuteEx(@ShExecInfo) then
begin { on execute le programme }
WaitForSingleObject(ShExecInfo.hProcess, INFINITE); { on attends un temps indefinie que l'appli s'arrete }
end;
result := True;
except
result := False;
end;
end; |
Je calle sur 3 choses (au moins) :
1) Le prototype dans mon .h (en gras)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class TForm1 : public TForm
{
__published: // Composants gérés par l'EDI
TImage *Image1;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
void __fastcall FormCreate(TObject *Sender);
private: // Déclarations utilisateur
public: // Déclarations utilisateur
__fastcall TForm1(TComponent* Owner);
bool Check_Pcx_Converter(void);
bool ExecuteWait(String, String, Boolean);
}; |
2) La fonction en elle-même (en gras)
Code:
1 2 3 4 5 6 7
| //---------------------------------------------------------------------------
//# bool TForm1::ExecuteWait(Prog , Parms, Voir)
// Execute an application and Wait until completion
// Voir Allows display or not
//---------------------------------------------------------------------------
bool TForm1::ExecuteWait(Prog, Parms:String, Voir:Boolean)
{ |
3) La définition de la classe ShExecInfo.
Si qqun peut éclairer ma lanterne cela ferait drôlement avancer mon Schmilblick.
A La compil j'obtiens [BCC32 Erreur] UnitImage.cpp(119): E2238 Déclaration multiple pour 'TForm1::ExecuteWait' sur la ligne
Code:
bool TForm1::ExecuteWait(Prog, Parms:String, Voir:Boolean)
et je ne comprend pas pourquoi. :aie: