????? ????? ????? "?????" ?? Win32

?????? ????????? ?????? ?????????
???? ???????: 178893 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

?? ???? ?????? ?? ???? ??????? ?????? ?? ????? ???? ???? ??????? ??? ????????? inter-process ????? ???????. ??? ???? ??? ?? ??? ???? ???? ???? ???? ????? ??????? ???? ???? ?? ????? ????? ?? ?? ?? ???? ???? ??? ??????. ?????? ?? ???? ??? ????? ?????? "?????" ????? ????? ????? ?? Win32 ???? ????? ????? ??????? ?????? ?? ?? ??????? ?????? ???? ????? ?? ????? ???????.

??????? ????

?????? 32-?? (? 16 ?? ???????? ??? Windows 95)

??? Win32 ? promises ???? ??????? ?????? ??????? ???????? ?? ??? ????? ??? ??? ????? ?????. ??? ?? ? ??? ????? ?? ???? ???? ???? ????? ???? ?????? ?????? ?? ??? ???????? ?? ????????? ??? ????? ?? ????? ??????? ??? ????? ???? ??? ???? ???? ??????? ????? DLL ????? ?????? ?????? ??????? ?????? PROCESS_DETACH ?????? ???. ??? ????? ???? ???? ??? ???? ????? ??? ??????? ??? Windows 95 ? Windows NT.

??? ??? ??? ????? ????? ????? ? ???? ??????? ???????:
  1. ??? WM_CLOSE ??? ???? ???????? ??????? ?????? ???????? ?? ??? ??????? ???? ???? ????? ?????. ?????? ??????? Windows ?????? ?? ??? ??????? ?? ???? ????? ?????.

    ??????: ??????? ??????? ???? ?????? WM_CLOSE ????? ??? ?? ??? ??? ?? ?????? ????? ????.

    ?????? EnumWindows() ????? ???????? ?????. ?? ????? ?? ????? ?? ??????? ?????? ???? ?????? ?? ??? ??? ???????? ?????? ????? ??????? ???? ???? ????? ?????. ????? ?????? ???? ?? ???? ??????? GetWindowThreadProcessId(). ??? ????? "??????" ? ?????? PostMessage() ?? SendMessageTimeout() ???? ????? WM_CLOSE ??? ??????.
  2. ?????? WaitForSingleObject() ??????? ???? ???????. ???? ?? ???????? ?? ???? ???? ???? ???? ?????? ?? ??????? ???? WM_CLOSE ??? ?? ??? ????? ???????. ???? ???? ?????? ????? ??? ???? (??? ?? WaitForSingleObject() ?? ?? SendMessageTimeout()) ???? ???? ??????? ????????? ??? ???? ?????? ?? ????? ???? ?? ??????? ?? ????????? ?????? WM_CLOSE.
  3. ??? ???? ???? ??????? WAIT_OBJECT_0 ?? ??????? ????? ???? ?????. ??? ???? ???? ??????? WAIT_TIMEOUT ?? ??? ???? ??????? TerminateProcess() ??? ????? ????? ???????.

    ??????: ??? ?? ??? getting3 ????? ???? ?? WaitForSingleObject() ?????? ?? WAIT_OBJECT_0 ?? WAIT_TIMEOUT ??????? GetLastError() ?????? ?????.
???? ??????? ??????? ???? ???? ??????? ???? ???????? ???? ?????? ????? (????? ??????? ????? ???? ?? IPC ?? ???? ????????).

??????? 16 ?? (??? Windows NT)

???? ??????? ????? ????????? ??? 16 ?? ??? Windows 95, ??? ???? ???? ??????? Windows NT 16-?? ???? ???? ?????.

??? Windows NT ?? ????? ???? ????????? ??? 16 ?? ?? ???? DOS ????? (VDM). ???? ??? VDM ?????? Win32 (NTVDM) ??? Windows NT. ???? ????? NTVDM ??? ????? ?????. ????? ?????? ??? ???? ??? ????? ??? OpenProcess() ? ????? ????? ?? ?? ????? Win32. ??????? ?? ? ?? ?? ??????? 16 ?? ??? ??????? ?? VDM ?? ???? ???? ???? ????? ?? ????? ?? ????? ?????? ??? "?????? ??????" ?? OpenProcess(). ????? ?? ????? 16-?? ?? VDM ?????? 16-?? "??????" ? 32-?? ?? ???? ????? ???????. ???? ?????? ??? ???? ???? ?? ???? ??????? ???? ??????? ?????? VDMEnumTaskWOWEx(). ?????? ??? ???? ?? ?????????? ?????? ?????? ??????? ??????? ?? "????? ??????? ?? Microsoft:
175030????? ????? ??????? ?? Win32
?????? ????? ? ?????? ?????? ??? ????? ????? ??????? ??? 16-?? ??? Windows NT ????? ????? ????? NTVDM ??????. ????? ?????? ???? ?? ???? ????? ??????? ??????? ?????. ????? ??? ?????? ????? ??????? ??????? NTVDM (???? ?? KB ??????? 175030 ???????? ????? ????? ?? ???? ??????? ?? NTVDM). ?? downside ??? ??????? ?? ?? ??? ?????? ???? ??????? 16 ?? ???? ??? ??????? ?? ??? VDM. ??? ?? ??? ??? ????? ? ???? ????? ?????? ????? ???.

??? ??? ???? ?? ????? ????? ????? 16-?? ???? ??? ????? NTVDM ???? ??? ??????? ????? ??????:
  1. ??? WM_CLOSE ??? ???? ???????? ??????? ?????? ???? ?????? ??????? ? ???? ??? ??? ?????? ???? ????? ?????? ?????? 16 ?? ???? ???? ?? ????? ?????. ????? ???? ?????? ?????? ???? ???????? EnumWindows(). ?? ????? "?? ???????" ? ???? ??? ??? ??? ????? ??????? ?? ?????? ?????? ???? ????? ????? ?????? 16 ?? ???? ???? ?? ????? ?????. ???? ???????? ????? ??????? ?? ???? ????? ??????? ??????? NTVDM ????? 16-?? ??? ???????.
  2. ??? ????? ?? ??? ???? ???? ???? ????? ???? ??? ????? ???? ???????? ?? ???? ????? ????? 16-??. ????? ????? ???? ??? ???????? ????? ??????? ?? ????? (?????? ???? ????? ?????) ????? ????? ??????? ??? ??? ????. ??? ?? ????? ??????? ?????? ? ?? ??? ??? ??? ?? ???. ??? ?? ????? ??????, ?? ???? ???? ????? ???????.
  3. ????? ??????? ???? ?????? ??????? VDMTerminateTaskWOW() ?? Vdmdbg.dll ????. ?????? ????? ??????? ?? VDM ???? ?????? ???? 16 ??.
????? ??? ??????? ???? ??????? ????? ????? ????? 16-?? ???? ??? VDM ??? Windows NT. ??? ???? ??? ???? ???? ?? ????? ????? ?????? ???? Windows 16-?? ??? ?? ??? ??? ??? WOWExec ??? ??????? ?? VDM. ??? ??? ???? ?? ????? ????? cleanest ????? ????? 16-?? ??? Windows NT ??? ????? ????? VDM ?????. ??????: ??? ?? ????? ??? ??????? 16 ?? ????? ????? ?? ??????? CREATE_SEPARATE_WOW_VDM ?? CreateProcess().

??? ?????

????? ????????? ???????? ?????? ???????? ?????? ????? 16-?? ???????? 32-?? ???????? ??????? ??????? ?????: TerminateApp() ? Terminate16App(). TerminateApp() ???? ???? ????? 32-?? ???? (?? miliseconds). Terminate16App(). ?????? ??? ???????? ???????? ???? ??? ????? DLL ???? ???? ??????? ???????? ??? Windows NT ? Windows 95.
   //******************
   //Header
   //******************

   #include <windows.h>

   #define TA_FAILED 0
   #define TA_SUCCESS_CLEAN 1
   #define TA_SUCCESS_KILL 2
   #define TA_SUCCESS_16 3

   DWORD WINAPI TerminateApp( DWORD dwPID, DWORD dwTimeout ) ;
   DWORD WINAPI Terminate16App( DWORD dwPID, DWORD dwThread,
                        WORD w16Task, DWORD dwTimeout );

   //******************
   //Source
   //******************

   #include "TermApp.h"
   #include <vdmdbg.h>

   typedef struct
   {
      DWORD   dwID ;
      DWORD   dwThread ;
   } TERMINFO ;

   // Declare Callback Enum Functions.
   BOOL CALLBACK TerminateAppEnum( HWND hwnd, LPARAM lParam ) ;

   BOOL CALLBACK Terminate16AppEnum( HWND hwnd, LPARAM lParam ) ;

   /*----------------------------------------------------------------
   DWORD WINAPI TerminateApp( DWORD dwPID, DWORD dwTimeout )

   Purpose:
      Shut down a 32-Bit Process (or 16-bit process under Windows 95)

   Parameters:
      dwPID
         Process ID of the process to shut down.

      dwTimeout
         Wait time in milliseconds before shutting down the process.

   Return Value:
      TA_FAILED - If the shutdown failed.
      TA_SUCCESS_CLEAN - If the process was shutdown using WM_CLOSE.
      TA_SUCCESS_KILL - if the process was shut down with
         TerminateProcess().
      NOTE:  See header for these defines.
   ----------------------------------------------------------------*/ 
   DWORD WINAPI TerminateApp( DWORD dwPID, DWORD dwTimeout )
   {
      HANDLE   hProc ;
      DWORD   dwRet ;

      // If we can't open the process with PROCESS_TERMINATE rights,
      // then we give up immediately.
      hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE,
         dwPID);

      if(hProc == NULL)
      {
         return TA_FAILED ;
      }

      // TerminateAppEnum() posts WM_CLOSE to all windows whose PID
      // matches your process's.
      EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) dwPID) ;

      // Wait on the handle. If it signals, great. If it times out,
      // then you kill it.
      if(WaitForSingleObject(hProc, dwTimeout)!=WAIT_OBJECT_0)
         dwRet=(TerminateProcess(hProc,0)?TA_SUCCESS_KILL:TA_FAILED);
      else
         dwRet = TA_SUCCESS_CLEAN ;

      CloseHandle(hProc) ;

      return dwRet ;
   }

   /*----------------------------------------------------------------
   DWORD WINAPI Terminate16App( DWORD dwPID, DWORD dwThread,
                        WORD w16Task, DWORD dwTimeout )

   Purpose:
      Shut down a Win16 APP.

   Parameters:
      dwPID
         Process ID of the NTVDM in which the 16-bit application is
         running.

      dwThread
         Thread ID of the thread of execution for the 16-bit
         application.

      w16Task
         16-bit task handle for the application.

      dwTimeout
         Wait time in milliseconds before shutting down the task.

   Return Value:
      If successful, returns TA_SUCCESS_16
      If unsuccessful, returns TA_FAILED.
      NOTE:  These values are defined in the header for this
      function.

   NOTE:
      You can get the Win16 task and thread ID through the
      VDMEnumTaskWOW() or the VDMEnumTaskWOWEx() functions.
   ----------------------------------------------------------------*/ 
   DWORD WINAPI Terminate16App( DWORD dwPID, DWORD dwThread,
                        WORD w16Task, DWORD dwTimeout )
   {
      HINSTANCE      hInstLib ;
      TERMINFO      info ;

      // You will be calling the functions through explicit linking
      // so that this code will be binary compatible across
      // Win32 platforms.
      BOOL (WINAPI *lpfVDMTerminateTaskWOW)(DWORD dwProcessId,
         WORD htask) ;

      hInstLib = LoadLibraryA( "VDMDBG.DLL" ) ;
      if( hInstLib == NULL )
         return TA_FAILED ;

      // Get procedure addresses.
      lpfVDMTerminateTaskWOW = (BOOL (WINAPI *)(DWORD, WORD ))
         GetProcAddress( hInstLib, "VDMTerminateTaskWOW" ) ;

      if( lpfVDMTerminateTaskWOW == NULL )
      {
         FreeLibrary( hInstLib ) ;
         return TA_FAILED ;
      }

      // Post a WM_CLOSE to all windows that match the ID and the
      // thread.
      info.dwID = dwPID ;
      info.dwThread = dwThread ;
      EnumWindows((WNDENUMPROC)Terminate16AppEnum, (LPARAM) &info) ;

      // Wait.
      Sleep( dwTimeout ) ;

      // Then terminate.
      lpfVDMTerminateTaskWOW(dwPID, w16Task) ;

      FreeLibrary( hInstLib ) ;
      return TA_SUCCESS_16 ;
   }

   BOOL CALLBACK TerminateAppEnum( HWND hwnd, LPARAM lParam )
   {
      DWORD dwID ;

      GetWindowThreadProcessId(hwnd, &dwID) ;

      if(dwID == (DWORD)lParam)
      {
         PostMessage(hwnd, WM_CLOSE, 0, 0) ;
      }

      return TRUE ;
   }

   BOOL CALLBACK Terminate16AppEnum( HWND hwnd, LPARAM lParam )
   {
      DWORD      dwID ;
      DWORD      dwThread ;
      TERMINFO   *termInfo ;

      termInfo = (TERMINFO *)lParam ;

      dwThread = GetWindowThreadProcessId(hwnd, &dwID) ;

      if(dwID == termInfo->dwID && termInfo->dwThread == dwThread )
      {
         PostMessage(hwnd, WM_CLOSE, 0, 0) ;
      }

      return TRUE ;
   }
				

???????

???? ???????: 178893 - ????? ??? ??????: 25/????? ??????/1425 - ??????: 2.4
????? ???
  • Microsoft Win32 ????? ????? ???????, ????? ?????? ??:
    • Microsoft Windows 95
    • Microsoft Windows NT 4.0
    • the operating system: Microsoft Windows 2000
    • the operating system: Microsoft Windows XP
????? ??????: 
kbmt kbhowto kbkernbase kbthread KB178893 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????178893

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com