Précédent   Forum du club des développeurs et IT Pro > Environnements de développement > Delphi > Langage
Langage Tout ce qui concerne le langage (POO, syntaxe, message d'erreur...)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 30/11/2012, 15h21   #1
bvsud
 
Inscription : avril 2004
Messages : 181
Détails du profil
Informations forums :
Inscription : avril 2004
Messages : 181
Points : -1
Points : -1
Par défaut Pb de paramétrage d'un CreateProcess()

Bonjour à tous

Ce code de CreateProcess() n'attend pas la fin du processus fils pour continuer. Même avec le flag CREATE_SUSPENDED. Comment initialiser celui-ci ?

Le code :
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
25
26
27
 
  FillChar(Startupinfo,Sizeof(TStartupinfo),0);
  Startupinfo.cb:=Sizeof(TStartupInfo);
  StartupInfo.wShowWindow := SW_SHOWMAXIMIZED;
  StartupInfo.dwFlags := {STARTF_USESHOWWINDOW OR} CREATE_SUSPENDED;  // N'attend qd-même pas ! 
 
 
 
  Processus := 'NOTEPAD'; 
  Parametre := ''; 
 
  Retour := CreateProcess(nil,
                         nil; // PChar(Parametre),
  	 	         nil,
                         nil,
                         false,
                         normal_priority_class,
                         nil,
                         PChar(Rep),
                         Startupinfo,ProcessInfo);
 
 
  CASE Retour OF
      True :
          begin
 
//etc.
Y a-t-il moyen d'éviter cette API, avec Delphi ? Appeler un prog ET attendre qu'il rende la main ?

Merci :hello:
bvsud est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2012, 16h07   #2
guillemouze
Membre chevronné
 
Avatar de guillemouze
 
Inscription : novembre 2004
Messages : 534
Détails du profil
Informations personnelles :
Âge : 30
Localisation : France, Loire Atlantique (Pays de la Loire)

Informations forums :
Inscription : novembre 2004
Messages : 534
Points : 698
Points : 698
tu trouvera la solution ici : http://delphi.developpez.com/faq/?pa...oleapplication
guillemouze est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2012, 16h28   #3
bvsud
 
Inscription : avril 2004
Messages : 181
Détails du profil
Informations forums :
Inscription : avril 2004
Messages : 181
Points : -1
Points : -1
Bon sang !

On ne vous a jamais dit que vous avez du génie, sur ce forum ?
bvsud est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2012, 17h53   #4
bvsud
 
Inscription : avril 2004
Messages : 181
Détails du profil
Informations forums :
Inscription : avril 2004
Messages : 181
Points : -1
Points : -1
Citation:
Envoyé par guillemouze Voir le message
C'est bizarre... Delphi me refuse les paramètres si je les utilise en variables :



Pourquoi ?
bvsud est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2012, 19h34   #5
guillemouze
Membre chevronné
 
Avatar de guillemouze
 
Inscription : novembre 2004
Messages : 534
Détails du profil
Informations personnelles :
Âge : 30
Localisation : France, Loire Atlantique (Pays de la Loire)

Informations forums :
Inscription : novembre 2004
Messages : 534
Points : 698
Points : 698
peut être parce que c'est le mauvais ordre des paramètres, le 3ème est du type "LPSECURITY_ATTRIBUTES". Ne serait-ce pas
Code :
1
2
3
CreateProcess('"Notepad.exe"', '"c:\test.txt"', Nil, ...)
plutot que 
CreateProcess(Nil, '"Notepad.exe"', '"c:\test.txt"', ...)
C'est quoi le message du compilateur ?
guillemouze est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2012, 13h59   #6
bvsud
 
Inscription : avril 2004
Messages : 181
Détails du profil
Informations forums :
Inscription : avril 2004
Messages : 181
Points : -1
Points : -1
C'est bon

Mon code (provisoire) :
Code :
1
2
3
4
5
6
7
8
9
10
 
  StartInfo.wShowWindow := SW_SHOWMAXIMIZED;
  FillChar(StartInfo,SizeOf(StartInfo),#0);
  StartInfo.cb     := SizeOf(StartInfo);
 
  Application.Minimize;
 
  { Lancement de la ligne de commande }
  If CreateProcess(Nil,'"c:\Program Files (x86)\IDM Computer Solutions\UltraEdit-32\UEDIT32.EXE" "Z-Net.TXT"'
                   , Nil, Nil, False, 0, Nil, Nil, StartInfo, ProcessInfo) then
... sauf que l'éditeur n'est pas paramétré SW_SHOWMAXIMIZED . Mais je vais y arriver. L'essentiel est de pouvoir utiliser des variable
bvsud est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2012, 20h03   #7
bvsud
 
Inscription : avril 2004
Messages : 181
Détails du profil
Informations forums :
Inscription : avril 2004
Messages : 181
Points : -1
Points : -1
Voici le code qui fonctionne, et stoppe bien mon appli en attendant le retour du processus appelé :

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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
Procedure Appel_6;
Var  StartInfo   : TStartupInfo;
     ProcessInfo : TProcessInformation;
     Fin         : Boolean;
     Ligne_Cmd : string;
 
begin
 
  FillChar(StartInfo,SizeOf(StartInfo),#0);
  StartInfo.cb     := SizeOf(StartInfo);
 
  Form1.Visible := False;
 
  Ligne_Cmd := PCHar(Nom_Editeur)  + ' ' + PChar(F_Cible);
 
  If CreateProcess(Nil, PChar(Ligne_Cmd)
                   , Nil, Nil, False, 0, Nil, Nil, StartInfo, ProcessInfo) then
 
  Begin
      Fin := False;
 
      Repeat
        Case WaitForSingleObject(ProcessInfo.hProcess, 200)Of
          WAIT_OBJECT_0 :  Fin := True; { L'application est terminée, on sort }
          WAIT_TIMEOUT  :  ;            { elle n'est pas terminée, on continue d'attendre }
        End;
 
        Application.ProcessMessages;
      Until Fin;
    End
  Else
      begin
          RaiseLastOSError;
          Form1.Visible := True;
          Application.ShowMainForm := True;
      end;
 
  Form1.Visible := True;
  SetForegroundWindow(Handle_App);
 
End;
Seul pépin : le prog appelé (UltraEdit32) n'apparaît pas en SHOW_MAXIMIZED. Après la routine, qui doit "déconfigurer" StartupInfo, UltraEdit apparaît systématiquement en mode "Non maximized" qd je l'appelle.

Plus que ce détail à revoir. Merci pour el coup de main :hello:
bvsud est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2012, 20h55   #8
tourlourou
Modérateur
 
Homme Yves Lemaire
Biologiste ; Progr(amateur)
Inscription : mars 2005
Messages : 1 674
Détails du profil
Informations personnelles :
Nom : Homme Yves Lemaire
Âge : 50
Localisation : France, Yvelines (Île de France)

Informations professionnelles :
Activité : Biologiste ; Progr(amateur)

Informations forums :
Inscription : mars 2005
Messages : 1 674
Points : 3 065
Points : 3 065
essaye en positionnant STARTF_USESHOWWINDOW dans TStartupInfo.dwFlags et SW_MAXIMIZE dans TStartupInfo.wShowWindow
__________________
Delphi 5 Pro / Win 98 PE - Code Typhon 2.80 64 Bits / Win 7 - Code Typhon 2.70 64 Bits / Ubuntu 12.04
tourlourou est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 03h32.


 
 
 
 
Partenaires

Hébergement Web