Bonjour

J'aimerais pouvoir ouvrir et fermer des programmes externe a partir de mon application. J'arrive a ouvrir sans probleme un programme externe grace a "CreateProcess" qui me permet en meme temps de recupérer le PID de l'application lancée. Mon probleme est de reussir a fermer cette application grace a ce PID. J'ai trouvé sur le net un code permettant de faire cela mais il doit comporter quelques erreur http://www.codeproject.com/cpp/kill_process.asp.

voici le code dans le .h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
vector<DWORD> processPid;
static bool CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
dans le .cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
void TFDemarrageInternet::lancerLogiciel()
{
   ...
   STARTUPINFO suInfo;
   PROCESS_INFORMATION procInfo;
   string m_Process;
   memset (&suInfo, 0, sizeof(suInfo));
   suInfo.cb = sizeof(suInfo);
   m_Process = cheminExecutable+executable;
 
   CreateProcess(m_Process.c_str(),NULL,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&suInfo,&procInfo);
   if (procInfo.dwThreadId == NULL)
      Application->MessageBoxA("Erreur","nope");
   else
      this->processPid = procInfo.dwProcessId;
   ...
}
 
void TFDemarrageInternet::quitterLogiciel()
{
   ...
  HANDLE ps = OpenProcess( SYNCHRONIZE|PROCESS_TERMINATE,FALSE, this->processPid);
  DWORD wndPid;
  string Title;
 
  // processPid = procInfo.dwProcessId;
 
  // This function enumerates all widows,
  // using the EnumWindowsProc callback
  // function, passing the PID of the process
  // you started earlier.
  EnumWindows(EnumWindowsProc, this->processPid);     <<<--- Pb de compilation
 
  CloseHandle(ps) ;
  ...
}
 
bool CALLBACK TFDemarrageInternet::EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
  DWORD wndPid;
  char * Title;
 
  // lParam = procInfo.dwProcessId;
 
  // This gets the windows handle and pid of enumerated window.
  GetWindowThreadProcessId(hwnd, &wndPid);
 
  // This gets the windows title text
  // from the window, using the window handle
  //CWnd::FromHandle(hwnd)->GetWindowText(Title);     	<<<---ne compile pas sous Builder 6
  GetClassName(hwnd,Title,50);				<<<---Remplacé par cette ligne là
  //  this makes sure that the PID matches that PID we started, and window
  // text exists, before we kill it . I don't think this is really needed,
  // I included it because some apps have more than one window.
  if ( wndPid == (DWORD)lParam && sizeof(Title) != 0)
  {
    //  Please kindly close this process
    ::PostMessage(hwnd, WM_CLOSE, 0, 0);
    return false;
  }
  else
  {
    // Keep enumerating
    return true;
  }
}
J'ai une erreur sur EnumWindows(EnumWindowsProc, this->processPid); .Le compilateur m'indique ceci

[C++ Erreur] F_DemarrageInternet.cpp(217): E2034 Impossible de convertir 'bool (__stdcall *)(void *,long)' en 'int (__stdcall *)()'
[C++ Erreur] F_DemarrageInternet.cpp(217): E2342 Mauvaise correspondance de type dans le paramètre 'lpEnumFunc' ('int (__stdcall *)()' désiré, 'bool (__stdcall *)(void *,long)' obtenu)

Je ne connaissais pas les fonctions CALLBACK avant, l'erreur vient peut etre de la. Sinon j'ai l'impression qu'il y a plus simple, n'existerait-il pas une fonction ou une commande windows permettant de quitter une application grace a son PID ?

merci d'avance.