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.

173 lines
4.4 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. main.cpp
  5. Abstract:
  6. This file contains the implementation of the WinMain function for HelpSvc.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 03/14/2000
  9. created
  10. ******************************************************************************/
  11. #include "stdafx.h"
  12. #include <SearchEngineLib.h>
  13. #include <NetSearchConfig.h>
  14. #include <ParamConfig.h>
  15. #include <RemoteConfig.h>
  16. #include <NetSW.h>
  17. #include <initguid.h>
  18. #include "msscript.h"
  19. #include "HelpServiceTypeLib.h"
  20. #include "HelpServiceTypeLib_i.c"
  21. BEGIN_OBJECT_MAP(ObjectMap)
  22. OBJECT_ENTRY(CLSID_NetSearchWrapper, SearchEngine::WrapperNetSearch)
  23. END_OBJECT_MAP()
  24. /////////////////////////////////////////////////////////////////////////////
  25. static HRESULT ProcessArguments( int argc ,
  26. LPCWSTR* argv )
  27. {
  28. __HCP_FUNC_ENTRY( "ProcessArguments" );
  29. HRESULT hr;
  30. int i;
  31. bool fCOM_reg = false;
  32. bool fCOM_unreg = false;
  33. bool fRun = true;
  34. for(i=1; i<argc; i++)
  35. {
  36. LPCWSTR szArg = argv[i];
  37. if(szArg[0] == '-' ||
  38. szArg[0] == '/' )
  39. {
  40. szArg++;
  41. if(_wcsicmp( szArg, L"UnregServer" ) == 0)
  42. {
  43. fCOM_unreg = true;
  44. fRun = false;
  45. continue;
  46. }
  47. if(_wcsicmp( szArg, L"RegServer" ) == 0)
  48. {
  49. fCOM_reg = true;
  50. fRun = false;
  51. continue;
  52. }
  53. }
  54. }
  55. //////////////////////////////////////////////////////////////////////
  56. if(fCOM_reg ) _Module.RegisterServer ( TRUE, FALSE, NULL );
  57. if(fCOM_unreg) _Module.UnregisterServer( NULL );
  58. if(fRun)
  59. {
  60. #ifdef DEBUG
  61. _Module.ReadDebugSettings();
  62. #endif
  63. DEBUG_AppendPerf( DEBUG_PERF_HELPHOST, "Start" );
  64. __MPC_EXIT_IF_METHOD_FAILS(hr, _Module.RegisterClassObjects( CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE ));
  65. //
  66. // Extract the connection information from the command line and return a instance of ourself.
  67. //
  68. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHUserProcess::SendResponse( argc, argv ));
  69. _Module.Start( FALSE );
  70. DEBUG_AppendPerf( DEBUG_PERF_HELPHOST, "Shutdown" );
  71. DEBUG_DumpPerf ( L"%WINDIR%\\TEMP\\HELPHOST_perf_counters.txt" );
  72. }
  73. //////////////////////////////////////////////////////////////////////
  74. hr = S_OK;
  75. __HCP_FUNC_CLEANUP;
  76. __HCP_FUNC_EXIT(hr);
  77. }
  78. extern "C" int WINAPI wWinMain( HINSTANCE hInstance ,
  79. HINSTANCE hPrevInstance,
  80. LPWSTR lpCmdLine ,
  81. int nShowCmd )
  82. {
  83. HRESULT hr;
  84. int argc;
  85. LPCWSTR* argv;
  86. if(SUCCEEDED(hr = ::CoInitializeEx( NULL, COINIT_MULTITHREADED ))) // We need to be a multi-threaded application.
  87. {
  88. if(SUCCEEDED(hr = ::CoInitializeSecurity( NULL ,
  89. -1 , // We don't care which authentication service we use.
  90. NULL ,
  91. NULL ,
  92. RPC_C_AUTHN_LEVEL_CONNECT, // We want to identify the callers.
  93. RPC_C_IMP_LEVEL_DELEGATE , // We want to be able to forward the caller's identity.
  94. NULL ,
  95. EOAC_DYNAMIC_CLOAKING , // Let's use the thread token for outbound calls.
  96. NULL )))
  97. {
  98. __MPC_TRACE_INIT();
  99. g_NTEvents.Init( L"HELPHOST" );
  100. //
  101. // Parse the command line.
  102. //
  103. if(SUCCEEDED(hr = MPC::CommandLine_Parse( argc, argv )))
  104. {
  105. //
  106. // Initialize ATL modules.
  107. //
  108. _Module.Init( ObjectMap, hInstance, NULL, 0, 0 );
  109. //
  110. // Initialize MPC module.
  111. //
  112. if(SUCCEEDED(hr = MPC::_MPC_Module.Init()))
  113. {
  114. //
  115. // Process arguments.
  116. //
  117. hr = ProcessArguments( argc, argv );
  118. MPC::_MPC_Module.Term();
  119. }
  120. _Module.Term();
  121. MPC::CommandLine_Free( argc, argv );
  122. }
  123. __MPC_TRACE_TERM();
  124. }
  125. ::CoUninitialize();
  126. }
  127. return FAILED(hr) ? 10 : 0;
  128. }