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.

92 lines
3.2 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. lib.cpp
  5. Abstract:
  6. This file contains the implementation of the HCApi Library.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 04/15/2000
  9. created
  10. ******************************************************************************/
  11. #include "StdAfx.h"
  12. ////////////////////////////////////////////////////////////////////////////////
  13. static const WCHAR c_HelpCtr[] = HC_ROOT_HELPSVC_BINARIES L"\\HelpCtr.exe";
  14. ////////////////////////////////////////////////////////////////////////////////
  15. HRESULT HCAPI::OpenConnection( /*[out]*/ CComPtr<IPCHHelpHost>& ipc )
  16. {
  17. __HCP_FUNC_ENTRY( "HCAPI::OpenConnection" );
  18. HRESULT hr;
  19. PROCESS_INFORMATION piProcessInformation;
  20. STARTUPINFOW siStartupInfo;
  21. CLSID clsidCaller;
  22. ::ZeroMemory( (PVOID)&piProcessInformation, sizeof( piProcessInformation ) );
  23. ::ZeroMemory( (PVOID)&siStartupInfo , sizeof( siStartupInfo ) ); siStartupInfo.cb = sizeof( siStartupInfo );
  24. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CoCreateGuid( &clsidCaller ));
  25. //
  26. // Create the process, passing the clsid to locate the IPCHHelpHost object. Try contacting the process for 10 seconds, then quit.
  27. //
  28. {
  29. CComBSTR bstrCaller( clsidCaller );
  30. MPC::wstring strExe ( c_HelpCtr ); MPC::SubstituteEnvVariables( strExe );
  31. int iRetries = 100;
  32. strExe += L" -Controlled ";
  33. strExe += SAFEBSTR( bstrCaller );
  34. __MPC_EXIT_IF_CALL_RETURNS_FALSE(hr, ::CreateProcessW( NULL ,
  35. (LPWSTR)strExe.c_str() ,
  36. NULL ,
  37. NULL ,
  38. FALSE ,
  39. NORMAL_PRIORITY_CLASS,
  40. NULL ,
  41. NULL ,
  42. &siStartupInfo ,
  43. &piProcessInformation ));
  44. while(iRetries--)
  45. {
  46. CComPtr<IRunningObjectTable> rt;
  47. CComPtr<IMoniker> moniker;
  48. CComPtr<IUnknown> obj;
  49. ::Sleep( 100 );
  50. __MPC_EXIT_IF_METHOD_FAILS(hr, ::GetRunningObjectTable( 0, &rt ));
  51. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CreateClassMoniker ( clsidCaller, &moniker ));
  52. if(SUCCEEDED(rt->GetObject( moniker, &obj )) && obj)
  53. {
  54. __MPC_SET_ERROR_AND_EXIT(hr, obj.QueryInterface( &ipc ));
  55. }
  56. }
  57. }
  58. hr = REGDB_E_CLASSNOTREG;
  59. __HCP_FUNC_CLEANUP;
  60. if(piProcessInformation.hProcess) ::CloseHandle( piProcessInformation.hProcess );
  61. if(piProcessInformation.hThread ) ::CloseHandle( piProcessInformation.hThread );
  62. __HCP_FUNC_EXIT(hr);
  63. }