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.

120 lines
3.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: wclass.cxx
  7. //
  8. // Contents:
  9. //
  10. //--------------------------------------------------------------------------
  11. #include "act.hxx"
  12. //+-------------------------------------------------------------------------
  13. //
  14. // CClassTableEntry::StartServerAndWait
  15. //
  16. //--------------------------------------------------------------------------
  17. HRESULT
  18. CClassTableEntry::StartServerAndWait(
  19. IN ACTIVATION_PARAMS * pActParams,
  20. IN CClsidData * pClsidData
  21. )
  22. {
  23. GUID Clsid;
  24. HANDLE hProcess;
  25. HANDLE hRegisterEvent;
  26. HRESULT hr;
  27. DWORD Status;
  28. BOOL bStatus;
  29. Clsid = Guid();
  30. hRegisterEvent = GetRegisterEvent();
  31. if ( ! hRegisterEvent )
  32. return E_OUTOFMEMORY;
  33. hProcess = 0;
  34. if ( SERVERTYPE_SURROGATE == pClsidData->ServerType() )
  35. {
  36. CSurrogateListEntry * pSurrogateListEntry;
  37. pSurrogateListEntry = gpSurrogateList->Lookup(
  38. NULL,
  39. NULL,
  40. pClsidData->Appid() );
  41. if ( pSurrogateListEntry )
  42. {
  43. bStatus = pSurrogateListEntry->LoadDll( pActParams, &hr );
  44. pSurrogateListEntry->Release();
  45. if ( bStatus )
  46. goto WaitForServer;
  47. }
  48. }
  49. hr = pClsidData->LaunchActivatorServer( &hProcess );
  50. WaitForServer:
  51. for (;;)
  52. {
  53. MSG Msg;
  54. //
  55. // Some wonder win9x code. Since we're running in the client's process
  56. // we have to let SendMessages in.
  57. //
  58. Status = SSMsgWaitForMultipleObjects(
  59. 1,
  60. &hRegisterEvent,
  61. FALSE,
  62. gServerStartTimeout,
  63. QS_SENDMESSAGE );
  64. //
  65. // If the Status index is beyond the array, then there is a
  66. // message available.
  67. //
  68. if ( Status != (DWORD)(WAIT_OBJECT_0 + 1) )
  69. break;
  70. (void) SSPeekMessage( &Msg, 0, 0, 0, PM_NOREMOVE );
  71. }
  72. if ( (Status != WAIT_OBJECT_0) && hProcess )
  73. TerminateProcess( hProcess, 0 );
  74. if ( hProcess )
  75. CloseHandle( hProcess );
  76. if ( Status != WAIT_OBJECT_0 )
  77. return CO_E_SERVER_EXEC_FAILURE;
  78. return S_OK;
  79. }
  80. #define EVENTNAMEPREFIX "ACTSERVEREVENT"
  81. //+-------------------------------------------------------------------------
  82. //
  83. // CClassTableEntry::GetRegisterEvent
  84. //
  85. //--------------------------------------------------------------------------
  86. HANDLE
  87. CClassTableEntry::GetRegisterEvent()
  88. {
  89. HANDLE hEvent;
  90. char szEvent[sizeof(EVENTNAMEPREFIX)+GUIDSTR_MAX+1];
  91. memcpy( szEvent, EVENTNAMEPREFIX, sizeof(EVENTNAMEPREFIX) );
  92. wStringFromGUID2A( Guid(), &szEvent[sizeof(EVENTNAMEPREFIX)], GUIDSTR_MAX + 1 );
  93. hEvent = CreateEventA( NULL, FALSE, FALSE, szEvent );
  94. return hEvent;
  95. }