Leaked source code of windows server 2003
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.

147 lines
4.4 KiB

  1. //=--------------------------------------------------------------------------=
  2. // HtmlHlp.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // contains routines that we will find useful.
  13. //
  14. #include "pch.h"
  15. #include "VsHelp.h"
  16. SZTHISFILE
  17. #ifdef VS_HELP
  18. IVsHelpSystem *g_pIVsHelpSystem = NULL;
  19. //=--------------------------------------------------------------------------=
  20. // QueryStartupVisualStudioHelp [HtmlHelp helper]
  21. //=--------------------------------------------------------------------------=
  22. // Starts up Visual Studio help system
  23. //
  24. HRESULT QueryStartupVisualStudioHelp(IVsHelpSystem **ppIVsHelpSystem)
  25. {
  26. CHECK_POINTER(ppIVsHelpSystem);
  27. HRESULT hr = S_OK;
  28. IVsHelpInit *pIVSHelpInit = NULL;
  29. ENTERCRITICALSECTION1(&g_CriticalSection);
  30. // Check to see if we're already started. If so, no need to continue
  31. //
  32. if (g_pIVsHelpSystem)
  33. {
  34. goto CleanUp;
  35. }
  36. // Create an instance of the VsHelpServices package, if not already created
  37. //
  38. hr = ::CoCreateInstance(CLSID_VsHelpServices,
  39. NULL,
  40. CLSCTX_INPROC_SERVER,
  41. IID_IVsHelpSystem,
  42. (void**) &g_pIVsHelpSystem) ;
  43. if (FAILED(hr))
  44. {
  45. goto CleanUp;
  46. }
  47. ASSERT(g_pIVsHelpSystem, "g_pIVsHelpSystem is NULL even though hr was successful");
  48. if (!g_pIVsHelpSystem)
  49. {
  50. hr = E_FAIL;
  51. goto CleanUp;
  52. }
  53. //--- Initialize the help system.
  54. // Get the init interface pointer.
  55. //
  56. hr = g_pIVsHelpSystem->QueryInterface(IID_IVsHelpInit, (void**)&pIVSHelpInit);
  57. ASSERT(SUCCEEDED(hr), "QI to IVSHelpInit failed -- continuing anyway");
  58. if (SUCCEEDED(hr))
  59. {
  60. hr = pIVSHelpInit->LoadUIResources(g_lcidLocale);
  61. ASSERT(SUCCEEDED(hr), "LoadUIResources() failed (this will happen if you haven't run MSDN setup) -- continuing anyway");
  62. }
  63. hr = S_OK;
  64. CleanUp:
  65. LEAVECRITICALSECTION1(&g_CriticalSection);
  66. QUICK_RELEASE(pIVSHelpInit);
  67. if (SUCCEEDED(hr))
  68. {
  69. g_pIVsHelpSystem->AddRef();
  70. *ppIVsHelpSystem = g_pIVsHelpSystem;
  71. }
  72. return hr;
  73. }
  74. //=--------------------------------------------------------------------------=
  75. // VisualStudioShowHelpTopic [HtmlHelp helper]
  76. //=--------------------------------------------------------------------------=
  77. // Displays the help topic in Visual Studio's help window
  78. //
  79. HRESULT VisualStudioShowHelpTopic(const char *pszHelpFile, DWORD dwContextId, BOOL *pbHelpStarted)
  80. {
  81. HRESULT hr;
  82. IVsHelpSystem* pIVsHelpSystem = NULL;
  83. BSTR bstrHelpFile;
  84. // Hand back help started to signify that we were able to start the help
  85. // system. This is useful since the controls have no clue as to what
  86. // environment they are running under Visual Studio might not be around
  87. // in which case the control will call HtmlHelp directly.
  88. //
  89. if (pbHelpStarted)
  90. *pbHelpStarted = FALSE;
  91. hr = QueryStartupVisualStudioHelp(&pIVsHelpSystem);
  92. if (FAILED(hr))
  93. return hr;
  94. ASSERT(pIVsHelpSystem, "QI succeeded but return value is NULL");
  95. hr = pIVsHelpSystem->ActivateHelpSystem(0);
  96. ASSERT(SUCCEEDED(hr), "Failed to activate the help system");
  97. if (FAILED(hr))
  98. goto CleanUp;
  99. // With the help system successfully activated, signify to the caller
  100. // that the Visual Studio help mechanism should work
  101. //
  102. if (pbHelpStarted)
  103. *pbHelpStarted = TRUE;
  104. bstrHelpFile = BSTRFROMANSI(pszHelpFile);
  105. ASSERT(bstrHelpFile, "Out of memory allocating BSTR");
  106. hr = pIVsHelpSystem->DisplayTopicFromIdentifier(bstrHelpFile, dwContextId, VHS_Localize);
  107. SysFreeString(bstrHelpFile);
  108. ASSERT(SUCCEEDED(hr), "Failed to display help topic");
  109. if (FAILED(hr))
  110. goto CleanUp;
  111. CleanUp:
  112. QUICK_RELEASE(pIVsHelpSystem);
  113. return hr;
  114. }
  115. #endif // VS_HELP