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.

142 lines
3.5 KiB

  1. /******************************************************************************
  2. Copyright (c) 1993-1998 Microsoft Corporation
  3. Title: csrthrd.c - code to create a thread inside the server process
  4. *****************************************************************************/
  5. #include <nt.h>
  6. #include <ntrtl.h>
  7. #include <nturtl.h>
  8. #include <ntcsrsrv.h>
  9. #include <windows.h>
  10. typedef PVOID (NTAPI *ADD_SERVER_THREAD)(HANDLE, PCLIENT_ID, ULONG);
  11. /*
  12. ** Create a server thread
  13. */
  14. BOOLEAN CreateServerPlayingThread(PVOID ThreadStartRoutine)
  15. {
  16. CLIENT_ID ClientId;
  17. HANDLE hThread;
  18. hThread = NULL;
  19. RtlCreateUserThread(NtCurrentProcess(),
  20. NULL,
  21. (BOOLEAN)TRUE,
  22. 0,
  23. 0,
  24. 0,
  25. (PUSER_THREAD_START_ROUTINE)ThreadStartRoutine,
  26. NULL,
  27. &hThread,
  28. &ClientId);
  29. if (!hThread) {
  30. #if DBG
  31. OutputDebugStringA("WINMM: Server failed to create user thread\n");
  32. #endif
  33. return FALSE;
  34. } else {
  35. HMODULE hModCSR;
  36. ADD_SERVER_THREAD pCsrAddStaticServerThread;
  37. hModCSR = GetModuleHandleW((LPCWSTR)L"csrsrv.dll");
  38. #if DBG
  39. if (hModCSR == NULL) {
  40. OutputDebugStringA("WINMM: Could not get CSRSRV.DLL handle\n");
  41. DebugBreak();
  42. }
  43. #endif
  44. pCsrAddStaticServerThread =
  45. (ADD_SERVER_THREAD)GetProcAddress(hModCSR, "CsrAddStaticServerThread");
  46. if (pCsrAddStaticServerThread == NULL) {
  47. #if DBG
  48. OutputDebugStringA("WINMM: Could not get address if CsrAddStaticServerThread\n");
  49. DebugBreak();
  50. #endif
  51. return FALSE;
  52. }
  53. (*pCsrAddStaticServerThread)(hThread, &ClientId, 0);
  54. /*
  55. * Resume the sound thread now that we've initialising things.
  56. */
  57. NtResumeThread(hThread, NULL);
  58. //NtClose(hThread);
  59. return TRUE;
  60. }
  61. }
  62. HANDLE CreatePnpNotifyThread(PVOID ThreadStartRoutine)
  63. {
  64. CLIENT_ID ClientId;
  65. HANDLE hThread;
  66. hThread = NULL;
  67. RtlCreateUserThread(NtCurrentProcess(),
  68. NULL,
  69. (BOOLEAN)TRUE,
  70. 0,
  71. 0,
  72. 0,
  73. (PUSER_THREAD_START_ROUTINE)ThreadStartRoutine,
  74. NULL,
  75. &hThread,
  76. &ClientId);
  77. if (NULL == hThread)
  78. {
  79. #if DBG
  80. OutputDebugStringA("WINMM: Server failed to create PnpNotify thread\n");
  81. #endif
  82. return FALSE;
  83. } else {
  84. HMODULE hModCSR;
  85. ADD_SERVER_THREAD pCsrAddStaticServerThread;
  86. hModCSR = GetModuleHandleW((LPCWSTR)L"csrsrv.dll");
  87. #if DBG
  88. if (NULL == hModCSR)
  89. {
  90. OutputDebugStringA("WINMM: Could not get CSRSRV.DLL handle");
  91. DebugBreak();
  92. }
  93. #endif
  94. pCsrAddStaticServerThread =
  95. (ADD_SERVER_THREAD)GetProcAddress(hModCSR, "CsrAddStaticServerThread");
  96. if (pCsrAddStaticServerThread == NULL) {
  97. #if DBG
  98. OutputDebugStringA("WINMM: Could not get address if CsrAddStaticServerThread\n");
  99. DebugBreak();
  100. #endif
  101. return FALSE;
  102. }
  103. (*pCsrAddStaticServerThread)(hThread, &ClientId, 0);
  104. /*
  105. * Resume the sound thread now that we've initialising things.
  106. */
  107. NtResumeThread(hThread, NULL);
  108. //NtClose(hThread);
  109. return hThread;
  110. }
  111. }