Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
End a process in Win2K/WinXP
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00708380
Message ID:
00708465
Vues:
13
This message has been marked as a message which has helped to the initial question of the thread.
>>Hi Ed,
>>While it's true that TerminateProcess is the hand grenade approach, it sounds like that may be what is needed. I would think that a WM_CLOSE/WM_QUIT would be passed along to the control when VFP receives it. From the explanation, it looks like that is being ignored.
>>
> Which appears to be the case - even, it seems, by design! However, I can't seem to get it to return the hWnd using your code. I consistently get a return of 0.

If you really want VFP to kill itself off via TerminateProcess(), you might try the following snippet:
DECLARE INTEGER GetCurrentProcess IN WIN32API
DECLARE INTEGER TerminateProcess IN WIN32API INTEGER hProcess, INTEGER uExitCode
CLOSE DATABASE ALL
CLOSE ALL
FLUSH
=TerminateProcess(GetCurrentProcess(),99) && 99 can be any number you like
If you discover that the ActiveX control is running on a separate thread from VFP, you could use the following to try just killing off that thread:
DECLARE INTEGER GetCurrentProcessId IN WIN32API
DECLARE INTEGER GetCurrentProcess IN WIN32API
DECLARE INTEGER GetCurrentThreadId IN WIN32API
DECLARE INTEGER TerminateThread IN WIN32API INTEGER hThread, INTEGER uExitCode
DECLARE INTEGER GetWindowThreadProcessId IN WIN32API INTEGER hWnd, INTEGER @ lpdwProcessID
DECLARE INTEGER OpenThread IN WIN32API INTEGER dwDesiredAccess, ;
   INTEGER bInheritHandle, ;
   INTEGER dwThreadID
#DEFINE THREAD_TERMINATE 0x1
*
*  I assume that you've saved the hWnd of the ActiveX in nActiveXhWnd
*
LOCAL nProcessID, nThreadID, nThreadHandle
nProcessID = 0
nThreadID = GetWindowThreadProcessId(nActiveXhWnd, @nProcessID)
IF BITOR(nProcessID,0) = BITOR(GetCurrentProcessId(),0) 
   && ActiveX runs in process
   IF ! (BITOR(nThreadID,0) = BITOR(GetCurrentThreadId(),0))
      && ActiveX runs on its own thread
      nThreadHandle = OpenThread(THREAD_TERMINATE,1,nThreadID)
      IF nThreadHandle # 0
         =TerminateThread(nThreadHandle,99)
      ELSE
         * Unable to open thread with TERMINATE permission
      ENDIF
   ELSE
      * ActiveX runs on the same thread as VFP - kill at your own risk
      * since you'll kill the VFP session, too.
      * If you want to get VFP to commit hara-kiri, add code to close files
      * and release thingies, and after that, uncomment the next line:
      * =TerminateThread(GetCurrentThread(),99)
   ENDIF
ELSE
   * ActiveX runs on an out-of-process server; you need to kill the process
   * running the ActiveX component, and you may need to play with access
   * tokens in order to get the necessary permissions under NT-family OSes
   * If you want to get VFP to commit hara-kiri, add code to close files
   * and release thingies, and after that, uncomment the next line:
   * =TerminateProcess(GetCurrentProcess(),99)
   * There's code in my API_APPRUN class to kill another process
ENDIF
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform