Leaked source code of windows server 2003
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.

244 lines
8.1 KiB

  1. /* mcitest.c - WinMain(), main dialog box and support code for MCITest.
  2. *
  3. * MCITest is a Windows with Multimedia sample application illustrating
  4. * the use of the Media Control Interface (MCI). MCITest puts up a dialog
  5. * box allowing you to enter and execute MCI string commands.
  6. *
  7. * (C) Copyright (c) 1991-1998 Microsoft Corporation
  8. *
  9. * You have a royalty-free right to use, modify, reproduce and
  10. * distribute the Sample Files (and/or any modified version) in
  11. * any way you find useful, provided that you agree that
  12. * Microsoft has no warranty obligations or liability for any
  13. * Sample Application Files which are modified.
  14. */
  15. /*----------------------------------------------------------------------------*\
  16. | mcitest.c - A testbed for MCI |
  17. | |
  18. | |
  19. | History: |
  20. | 01/01/88 toddla Created |
  21. | 03/01/90 davidle Modified quick app into MCI testbed |
  22. | 09/17/90 t-mikemc Added Notification box with 3 notification types |
  23. | 11/02/90 w-dougb Commented & formatted the code to look pretty |
  24. | 05/29/91 NigelT ported to Win32
  25. | |
  26. \*----------------------------------------------------------------------------*/
  27. /*----------------------------------------------------------------------------*\
  28. | |
  29. | i n c l u d e f i l e s |
  30. | |
  31. \*----------------------------------------------------------------------------*/
  32. #include "mcihwnd.h"
  33. CHAR aszMciWindow[] = MCI_GLOBAL_PROCESS;
  34. PGLOBALMCI base;
  35. /*
  36. // BOOL CreateMappedFile(void) INTERNAL
  37. //
  38. // Set up a global named file to use for interprocess communication.
  39. // This process will be the only one to write into this shared memory.
  40. // On exit the memory has been mapped, and our global variable set to
  41. // point to it. From here on in most of the work is done in WINMM,
  42. // including the window creation.
  43. */
  44. BOOL CreateMappedFile(void)
  45. {
  46. HANDLE hFileMapping;
  47. DWORD err;
  48. hFileMapping = CreateFileMapping(
  49. (HANDLE)-1, // put onto the paging file
  50. NULL, // security attributes
  51. PAGE_READWRITE,
  52. 0, // high order size
  53. sizeof(GLOBALMCI),// only need a few bytes
  54. aszMciWindow // name of file
  55. );
  56. dprintf3("hFileMapping from CreateFileMapping is %x", hFileMapping);
  57. if (!hFileMapping) {
  58. // Note: This prevents the module being run twice...
  59. // The second create will fail
  60. err = GetLastError();
  61. dprintf2("Error %d from CreateFileMapping", err);
  62. return FALSE;
  63. }
  64. base = MapViewOfFile( hFileMapping, FILE_MAP_WRITE,
  65. 0, 0, 0); // from beginning for total length
  66. dprintf3("Base address from MapViewOfFile is %x", base);
  67. if (!base) {
  68. err = GetLastError();
  69. dprintf2("Error %d from MapViewOfFile", err);
  70. return(FALSE);
  71. }
  72. memset(base, 0, sizeof(GLOBALMCI));
  73. base->dwGlobalProcessId = GetCurrentProcessId();
  74. base->dwGlobalThreadId = GetCurrentThreadId();
  75. dprintf3("Setting notify pid/tid to %x %x", base->dwGlobalProcessId, base->dwGlobalThreadId);
  76. return(TRUE);
  77. }
  78. //
  79. // MYCREATEEVENT
  80. //
  81. BOOL SrvCreateEvent(VOID)
  82. {
  83. SECURITY_ATTRIBUTES SA;
  84. HANDLE hEvent;
  85. SA.bInheritHandle = TRUE;
  86. SA.lpSecurityDescriptor = NULL;
  87. SA.nLength = sizeof(SA);
  88. hEvent = CreateEvent( &SA,
  89. TRUE, // Manual reset
  90. FALSE, // initially not signalled
  91. NULL); // no name
  92. if (hEvent) {
  93. dprintf2("Created shared event, handle is %8x", hEvent);
  94. base->hEvent = hEvent;
  95. return(TRUE);
  96. } else {
  97. #if DBG
  98. DWORD err;
  99. err = GetLastError();
  100. dprintf2("Error %d creating MCI shared event", err);
  101. #endif
  102. return(FALSE);
  103. }
  104. }
  105. //
  106. // MYCREATEMUTEX
  107. //
  108. BOOL SrvCreateMutex(VOID)
  109. {
  110. SECURITY_ATTRIBUTES SA;
  111. HANDLE hMutex;
  112. SA.bInheritHandle = TRUE;
  113. SA.lpSecurityDescriptor = NULL;
  114. SA.nLength = sizeof(SA);
  115. hMutex = CreateMutex( &SA,
  116. FALSE, // initially not owned
  117. NULL); // no name
  118. if (hMutex) {
  119. dprintf2("Created shared mutex, handle is %8x", hMutex);
  120. base->hMutex = hMutex;
  121. return(TRUE);
  122. } else {
  123. #if DBG
  124. DWORD err;
  125. err = GetLastError();
  126. dprintf2("Error %d creating MCI shared mutex", err);
  127. #endif
  128. return(FALSE);
  129. }
  130. }
  131. /*----------------------------------------------------------------------------*\
  132. | MAIN: |
  133. | |
  134. | Description: |
  135. | The main procedure for the app. After initializing, it just goes |
  136. | into a message-processing loop until it gets a WM_QUIT message |
  137. | (meaning the app was closed). |
  138. | |
  139. | Arguments: |
  140. | hInst instance handle of this instance of the app |
  141. | hPrev instance handle of previous instance, NULL if first |
  142. | szCmdLine null-terminated command line string |
  143. | sw specifies how the window is to be initially displayed |
  144. | |
  145. | Returns: |
  146. | The exit code as specified in the WM_QUIT message. |
  147. | |
  148. \*----------------------------------------------------------------------------*/
  149. typedef BOOL (* BOOLPROC)(void);
  150. int __cdecl main(
  151. int argc,
  152. char *argv[],
  153. char *envp[])
  154. {
  155. MSG Msg; /* Windows message structure */
  156. HANDLE hLib;
  157. BOOLPROC proc;
  158. // If we are in DEBUG mode, get debug level for this module
  159. dGetDebugLevel(aszAppName);
  160. #if DBG
  161. dprintf2("MCIHWND started (debug level %d)", __iDebugLevel);
  162. #endif
  163. /* Call the initialization procedure */
  164. /* We load the library explicitly to prevent module load causing */
  165. /* WINMM's DLL initialisation to be run. We have probably started */
  166. /* as a result of that initialisation. */
  167. if (!CreateMappedFile()) return 0;
  168. if (!SrvCreateEvent()) return 0; // Set up the shared event
  169. if (!SrvCreateMutex()) return 0; // Set up the shared mutex
  170. base->dwType = GMCI_MCIHWND;
  171. UnmapViewOfFile(base);
  172. base = NULL;
  173. hLib = LoadLibrary("WINMM");
  174. if (!hLib) {
  175. dprintf("MCIHWND failed to load WINMM");
  176. return(FALSE);
  177. }
  178. proc = (BOOLPROC)GetProcAddress(hLib, (LPCSTR)"mciSoundInit");
  179. if (NULL == proc) {
  180. dprintf("cannot get address of mciWndInit");
  181. return FALSE;
  182. }
  183. if (!(*proc)()) {
  184. dprintf("failure returned from mciWndInit");
  185. return FALSE;
  186. }
  187. dprintf4("MCIHWND now going into its message loop");
  188. /* Poll the event queue for messages */
  189. while (GetMessage(&Msg, NULL, 0, 0)) {
  190. /* Main message processing */
  191. dprintf4("Message received %8x Hwnd=%8x wParam=%8x lParam=%8x", Msg.message, Msg.hwnd, Msg.wParam, Msg.lParam);
  192. TranslateMessage(&Msg);
  193. DispatchMessage(&Msg);
  194. }
  195. dprintf2("MCIHWND exited its message loop");
  196. dprintf2(" Last message %8x Hwnd=%8x wParam=%8x lParam=%8x", Msg.message, Msg.hwnd, Msg.wParam, Msg.lParam);
  197. DebugBreak();
  198. dprintf1("MCIHWND should not be here...");
  199. return Msg.wParam;
  200. }