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.

239 lines
6.1 KiB

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