Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
3.8 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: killsvr.c
  6. * Content: kill dplay.exe
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 06-apr-95 craige initial implementation
  11. * 24-jun-95 craige kill all attached processes
  12. * 2-feb-97 andyco ported for dplaysvr.exe
  13. * 7-jul-97 kipo added non-console support
  14. *
  15. ***************************************************************************/
  16. #include <windows.h>
  17. #include <stdio.h>
  18. #include <conio.h>
  19. #include "dplaysvr.h"
  20. // only do printf's when built as a console app
  21. #ifdef NOCONSOLE
  22. #pragma warning(disable:4002)
  23. #define printf()
  24. #endif
  25. /*
  26. * sendRequest
  27. *
  28. * communicate a request to DPHELP
  29. */
  30. static BOOL sendRequest( LPDPHELPDATA req_phd )
  31. {
  32. LPDPHELPDATA phd;
  33. HANDLE hmem;
  34. HANDLE hmutex;
  35. HANDLE hackevent;
  36. HANDLE hstartevent;
  37. BOOL rc;
  38. /*
  39. * get events start/ack events
  40. */
  41. hstartevent = CreateEvent( NULL, FALSE, FALSE, DPHELP_EVENT_NAME );
  42. printf( "hstartevent = %08lx\n", hstartevent );
  43. if( hstartevent == NULL )
  44. {
  45. return FALSE;
  46. }
  47. hackevent = CreateEvent( NULL, FALSE, FALSE, DPHELP_ACK_EVENT_NAME );
  48. printf( "hackevent = %08lx\n", hackevent );
  49. if( hackevent == NULL )
  50. {
  51. CloseHandle( hstartevent );
  52. return FALSE;
  53. }
  54. /*
  55. * create shared memory area
  56. */
  57. hmem = CreateFileMapping( INVALID_HANDLE_VALUE, NULL,
  58. PAGE_READWRITE, 0, sizeof( DPHELPDATA ),
  59. DPHELP_SHARED_NAME );
  60. printf( "hmem = %08lx\n", hmem );
  61. if( hmem == NULL )
  62. {
  63. printf( "Could not create file mapping!\n" );
  64. CloseHandle( hstartevent );
  65. CloseHandle( hackevent );
  66. return FALSE;
  67. }
  68. phd = (LPDPHELPDATA) MapViewOfFile( hmem, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
  69. printf( "phd = %08lx\n", phd );
  70. if( phd == NULL )
  71. {
  72. printf( "Could not create view of file!\n" );
  73. CloseHandle( hmem );
  74. CloseHandle( hstartevent );
  75. CloseHandle( hackevent );
  76. return FALSE;
  77. }
  78. /*
  79. * wait for access to the shared memory
  80. */
  81. hmutex = OpenMutex( SYNCHRONIZE, FALSE, DPHELP_MUTEX_NAME );
  82. printf( "hmutex = %08lx\n", hmutex );
  83. if( hmutex == NULL )
  84. {
  85. printf( "Could not create mutex!\n" );
  86. CloseHandle( hmem );
  87. CloseHandle( hstartevent );
  88. CloseHandle( hackevent );
  89. return FALSE;
  90. }
  91. WaitForSingleObject( hmutex, INFINITE );
  92. /*
  93. * wake up DPHELP with our request
  94. */
  95. memcpy( phd, req_phd, sizeof( DPHELPDATA ) );
  96. printf( "waking up DPHELP\n" );
  97. if( SetEvent( hstartevent ) )
  98. {
  99. printf( "Waiting for response\n" );
  100. WaitForSingleObject( hackevent, INFINITE );
  101. memcpy( req_phd, phd, sizeof( DPHELPDATA ) );
  102. rc = TRUE;
  103. printf( "got response\n" );
  104. }
  105. else
  106. {
  107. printf( "Could not signal event to notify dplay.exe\n" );
  108. rc = FALSE;
  109. }
  110. /*
  111. * done with things
  112. */
  113. ReleaseMutex( hmutex );
  114. CloseHandle( hstartevent );
  115. CloseHandle( hackevent );
  116. CloseHandle( hmutex );
  117. CloseHandle( hmem );
  118. return rc;
  119. } /* sendRequest */
  120. // if the main entry point is called "WinMain" we will be built
  121. // as a windows app
  122. #ifdef NOCONSOLE
  123. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  124. LPSTR lpCmdLine, int nCmdShow)
  125. #else
  126. // if the main entry point is called "main" we will be built
  127. // as a console app
  128. int main( int argc, char *argv[] )
  129. #endif
  130. {
  131. HANDLE h;
  132. DPHELPDATA hd;
  133. h = OpenEvent( SYNCHRONIZE, FALSE, DPHELP_STARTUP_EVENT_NAME );
  134. if( h == NULL )
  135. {
  136. printf( "Helper not running\n" );
  137. return 0;
  138. }
  139. printf( "*** SUICIDE ***\n" );
  140. hd.req = DPHELPREQ_SUICIDE;
  141. sendRequest( &hd );
  142. return 0;
  143. }