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.

132 lines
3.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: U H I N I T . C P P
  7. //
  8. // Contents: Initialization routines for upnphost.
  9. //
  10. // Notes:
  11. //
  12. // Author: mbend 8 Aug 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "uhbase.h"
  18. #include "uhinit.h"
  19. static const WCHAR c_szClassObjectRegistrationEvent [] =
  20. L"UpnphostClassObjectRegistrationEvent";
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Function: HrNmCreateClassObjectRegistrationEvent
  24. //
  25. // Purpose: Create the named event that will be signaled after
  26. // our class objects have been registered.
  27. //
  28. // Arguments:
  29. // phEvent [out] Returned event handle
  30. //
  31. // Returns: S_OK or a Win32 error code.
  32. //
  33. // Author: shaunco 27 Jan 1998
  34. //
  35. // Notes:
  36. //
  37. HRESULT
  38. HrNmCreateClassObjectRegistrationEvent (
  39. HANDLE* phEvent)
  40. {
  41. Assert (phEvent);
  42. HRESULT hr = S_OK;
  43. // Create the name event and return it.
  44. //
  45. *phEvent = CreateEvent (NULL, FALSE, FALSE,
  46. c_szClassObjectRegistrationEvent);
  47. if (!*phEvent)
  48. {
  49. hr = HrFromLastWin32Error ();
  50. }
  51. TraceHr (ttidError, FAL, hr, FALSE,
  52. "HrNmCreateClassObjectRegistrationEvent");
  53. return hr;
  54. }
  55. //+---------------------------------------------------------------------------
  56. //
  57. // Function: HrNmWaitForClassObjectsToBeRegistered
  58. //
  59. // Purpose: For the event to be signaled if it can be opened.
  60. //
  61. // Arguments:
  62. // (none)
  63. //
  64. // Returns: S_OK or a Win32 error code.
  65. //
  66. // Author: shaunco 27 Jan 1998
  67. //
  68. // Notes:
  69. //
  70. HRESULT
  71. HrNmWaitForClassObjectsToBeRegistered ()
  72. {
  73. HRESULT hr = S_OK;
  74. // Try to open the named event. If it does not exist,
  75. // that's okay because we've probably already created and destroyed
  76. // it before this function was called.
  77. //
  78. HANDLE hEvent = OpenEvent (SYNCHRONIZE, FALSE,
  79. c_szClassObjectRegistrationEvent);
  80. if (hEvent)
  81. {
  82. // Now wait for the event to be signaled while pumping messages
  83. // as needed. We'll wait for up to 10 seconds. That should be
  84. // plenty of time for the class objects to be registered.
  85. //
  86. while (1)
  87. {
  88. const DWORD cMaxWaitMilliseconds = 10000; // 10 seconds
  89. DWORD dwWait = MsgWaitForMultipleObjects (1, &hEvent, FALSE,
  90. cMaxWaitMilliseconds, QS_ALLINPUT);
  91. if ((WAIT_OBJECT_0 + 1) == dwWait)
  92. {
  93. // We have messages to pump.
  94. //
  95. MSG msg;
  96. while (PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
  97. {
  98. DispatchMessage (&msg);
  99. }
  100. }
  101. else
  102. {
  103. // Wait is satisfied, or we had a timeout, or an error.
  104. //
  105. if (WAIT_TIMEOUT == dwWait)
  106. {
  107. hr = HRESULT_FROM_WIN32 (ERROR_TIMEOUT);
  108. }
  109. else if (0xFFFFFFFF == dwWait)
  110. {
  111. hr = HrFromLastWin32Error ();
  112. }
  113. break;
  114. }
  115. }
  116. CloseHandle (hEvent);
  117. }
  118. TraceHr (ttidError, FAL, hr, FALSE,
  119. "HrNmWaitForClassObjectsToBeRegistered");
  120. return hr;
  121. }