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.

243 lines
5.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1998 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. IASHelper.cpp
  7. Implementation of the following helper classes:
  8. And global functions:
  9. GetSdoInterfaceProperty - Get an interface property from a SDO
  10. through its ISdo interface
  11. FILE HISTORY:
  12. 2/18/98 byao Created
  13. */
  14. #include <limits.h>
  15. #include "stdafx.h"
  16. #include "helper.h"
  17. #include "resource.h"
  18. #include "IASHelper.h"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: IASGetSdoInterfaceProperty
  22. //
  23. // Synopsis: Get an interface property from a SDO through its ISdo interface
  24. //
  25. // Arguments: ISdo *pISdo - Pointer to ISdo
  26. // LONG lPropId - property id
  27. // REFIID riid - ref iid
  28. // void ** ppvObject - pointer to the requested interface property
  29. //
  30. // Returns: HRESULT -
  31. //
  32. // History: Created Header byao 2/12/98 11:12:55 PM
  33. //
  34. //+---------------------------------------------------------------------------
  35. HRESULT IASGetSdoInterfaceProperty(ISdo *pISdo,
  36. LONG lPropID,
  37. REFIID riid,
  38. void ** ppvInterface)
  39. {
  40. TRACE(_T("::IASGetSdoInterfaceProperty()\n"));
  41. VARIANT var;
  42. HRESULT hr;
  43. VariantInit(&var);
  44. VariantClear(&var);
  45. V_VT(&var) = VT_DISPATCH;
  46. V_DISPATCH(&var) = NULL;
  47. hr = pISdo->GetProperty(lPropID, &var);
  48. ReportError(hr, IDS_IAS_ERR_SDOERROR_GETPROPERTY, NULL);
  49. _ASSERTE( V_VT(&var) == VT_DISPATCH );
  50. // query the dispatch pointer for interface
  51. hr = V_DISPATCH(&var) -> QueryInterface( riid, ppvInterface);
  52. ReportError(hr, IDS_IAS_ERR_SDOERROR_QUERYINTERFACE, NULL);
  53. VariantClear(&var);
  54. return S_OK;
  55. }
  56. //////////////////////////////////////////////////////////////////////////////
  57. /*++
  58. int ShowErrorDialog(
  59. UINT uErrorID = 0
  60. , BSTR bstrSupplementalErrorString = NULL
  61. , HRESULT hr = S_OK
  62. , UINT uTitleID = 0
  63. , HWND hWnd = NULL
  64. , UINT uType = MB_OK | MB_ICONEXCLAMATION
  65. );
  66. Puts up an error dialog with varying degrees of detail
  67. Parameters:
  68. All parameters are optional -- in the worst case, you can simply call
  69. ShowErrorDialog();
  70. to put up a very generic error message.
  71. uErrorID
  72. The resource ID of the string to be used for the error message.
  73. Passing in 0 gives causes the default error message to be displayed.
  74. bstrSupplementalErrorString
  75. Pass in a string to print as the error message. Useful if you are
  76. receiving an error string from some other component you communicate with.
  77. hr
  78. If there is an HRESULT involved in the error, pass it in here so that
  79. a suitable error message based on the HRESULT can be put up.
  80. Pass in S_OK if the HRESULT doesn't matter to the error.
  81. uTitleID
  82. The resource ID of the string to be used for the error dialog title.
  83. Passing in 0 gives causes the default error dialog title to be displayed.
  84. pConsole
  85. If you are running within the main MMC context, pass in a valid IConsole pointer
  86. and ShowErrorDialog will use MMC's IConsole::MessageBox rather than the
  87. standard system MessageBox.
  88. hWnd
  89. Whatever you pass in here will be passed in as the HWND parameter
  90. to the MessageBox call.
  91. This is not used if you pass in an IConsole pointer.
  92. uType
  93. Whatever you pass in here will be passed in as the HWND parameter
  94. to the MessageBox call.
  95. Return:
  96. The standard int returned from MedsageBox.
  97. --*/
  98. //////////////////////////////////////////////////////////////////////////////
  99. #define IAS_MAX_STRING MAX_PATH
  100. int ShowErrorDialog(
  101. HWND hWnd
  102. , UINT uErrorID
  103. , BSTR bstrSupplementalErrorString
  104. , HRESULT hr
  105. , UINT uTitleID
  106. , UINT uType
  107. )
  108. {
  109. TRACE(_T("::ShowErrorDialog()\n"));
  110. int iReturnValue;
  111. TCHAR szError[IAS_MAX_STRING];
  112. TCHAR szTitle[IAS_MAX_STRING];
  113. int iLoadStringResult;
  114. HINSTANCE hInstance = _Module.GetResourceInstance();
  115. if( 0 == uTitleID )
  116. {
  117. uTitleID = IDS_IAS_ERR_ADVANCED;
  118. }
  119. iLoadStringResult = LoadString( hInstance, uTitleID, szTitle, IAS_MAX_STRING );
  120. _ASSERT( iLoadStringResult > 0 );
  121. if( 1 == uErrorID )
  122. {
  123. // Special case. We have no text to load from the resources.
  124. }
  125. else
  126. {
  127. if( 0 == uErrorID )
  128. {
  129. uErrorID = IDS_IAS_ERR_ADVANCED;
  130. }
  131. iLoadStringResult = LoadString( hInstance, uErrorID, szError, IAS_MAX_STRING );
  132. _ASSERT( iLoadStringResult > 0 );
  133. if( NULL != bstrSupplementalErrorString )
  134. {
  135. // Add some spacing.
  136. _tcscat( szError, _T(" ") );
  137. }
  138. }
  139. if( NULL != bstrSupplementalErrorString )
  140. {
  141. // We were passed a string with supplemental error info.
  142. _tcscat( szError, bstrSupplementalErrorString );
  143. }
  144. if( FAILED( hr ) )
  145. {
  146. // The HRESULT contains some information about the kind of failure.
  147. // We may want to change this later to provide more information
  148. // information based on the error that was returned.
  149. // We could have a map which defines relationships between error
  150. // ID's and the HRESULTS. That way we could provide the appropriate
  151. // error message for each HRESULT based on the context of which ID
  152. // was passed in.
  153. // For now, just print the error ID.
  154. TCHAR szErrorNumber[IAS_MAX_STRING];
  155. _stprintf( szErrorNumber, _T(" 0x%x"), hr );
  156. // Some spacing.
  157. _tcscat( szError, _T(" ") );
  158. _tcscat( szError, szErrorNumber );
  159. }
  160. if (!hWnd)
  161. {
  162. hWnd = GetDesktopWindow();
  163. }
  164. iReturnValue = ::MessageBox( hWnd, szError, szTitle, uType );
  165. return iReturnValue;
  166. }