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.

251 lines
6.0 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1999 **
  4. //*********************************************************************
  5. //
  6. // DEBUG.CPP - Implementation for CDebug
  7. //
  8. // HISTORY:
  9. //
  10. // 05/08/00 dane Created.
  11. //
  12. #include "precomp.h"
  13. #include "msobmain.h"
  14. #include "appdefs.h"
  15. #include "dispids.h"
  16. DISPATCHLIST DebugExternalInterface[] =
  17. {
  18. {L"Trace", DISPID_DEBUG_TRACE },
  19. {L"get_MsDebugMode", DISPID_DEBUG_ISMSDEBUGMODE },
  20. {L"get_OemDebugMode", DISPID_DEBUG_ISOEMDEBUGMODE }
  21. };
  22. /////////////////////////////////////////////////////////////
  23. // CDebug::CDebug
  24. CDebug::CDebug()
  25. {
  26. // Init member vars
  27. m_cRef = 0;
  28. m_fMsDebugMode = IsMsDebugMode( );
  29. m_fOemDebugMode = IsOEMDebugMode();
  30. }
  31. /////////////////////////////////////////////////////////////
  32. // CDebug::~CDebug
  33. CDebug::~CDebug()
  34. {
  35. MYASSERT(m_cRef == 0);
  36. }
  37. void
  38. CDebug::Trace(
  39. BSTR bstrVal
  40. )
  41. {
  42. pSetupDebugPrint( L"OOBE Trace", 0, NULL, bstrVal );
  43. #if 1
  44. if (m_fMsDebugMode)
  45. {
  46. ::MyTrace(bstrVal);
  47. }
  48. #endif
  49. }
  50. /////////////////////////////////////////////////////////////
  51. /////////////////////////////////////////////////////////////
  52. /////////////////////////////////////////////////////////////
  53. /////// IUnknown implementation
  54. ///////
  55. ///////
  56. /////////////////////////////////////////////////////////////
  57. // CDebug::QueryInterface
  58. STDMETHODIMP CDebug::QueryInterface(REFIID riid, LPVOID* ppvObj)
  59. {
  60. // must set out pointer parameters to NULL
  61. *ppvObj = NULL;
  62. if ( riid == IID_IUnknown)
  63. {
  64. AddRef();
  65. *ppvObj = (IUnknown*)this;
  66. return ResultFromScode(S_OK);
  67. }
  68. if (riid == IID_IDispatch)
  69. {
  70. AddRef();
  71. *ppvObj = (IDispatch*)this;
  72. return ResultFromScode(S_OK);
  73. }
  74. // Not a supported interface
  75. return ResultFromScode(E_NOINTERFACE);
  76. }
  77. /////////////////////////////////////////////////////////////
  78. // CDebug::AddRef
  79. STDMETHODIMP_(ULONG) CDebug::AddRef()
  80. {
  81. return ++m_cRef;
  82. }
  83. /////////////////////////////////////////////////////////////
  84. // CDebug::Release
  85. STDMETHODIMP_(ULONG) CDebug::Release()
  86. {
  87. return --m_cRef;
  88. }
  89. /////////////////////////////////////////////////////////////
  90. /////////////////////////////////////////////////////////////
  91. /////////////////////////////////////////////////////////////
  92. /////// IDispatch implementation
  93. ///////
  94. ///////
  95. /////////////////////////////////////////////////////////////
  96. // CDebug::GetTypeInfo
  97. STDMETHODIMP CDebug::GetTypeInfo(UINT, LCID, ITypeInfo**)
  98. {
  99. return E_NOTIMPL;
  100. }
  101. /////////////////////////////////////////////////////////////
  102. // CDebug::GetTypeInfoCount
  103. STDMETHODIMP CDebug::GetTypeInfoCount(UINT* pcInfo)
  104. {
  105. return E_NOTIMPL;
  106. }
  107. /////////////////////////////////////////////////////////////
  108. // CDebug::GetIDsOfNames
  109. STDMETHODIMP CDebug::GetIDsOfNames(REFIID riid,
  110. OLECHAR** rgszNames,
  111. UINT cNames,
  112. LCID lcid,
  113. DISPID* rgDispId)
  114. {
  115. HRESULT hr = DISP_E_UNKNOWNNAME;
  116. rgDispId[0] = DISPID_UNKNOWN;
  117. for (int iX = 0; iX < sizeof(DebugExternalInterface)/sizeof(DISPATCHLIST); iX ++)
  118. {
  119. if(lstrcmp(DebugExternalInterface[iX].szName, rgszNames[0]) == 0)
  120. {
  121. rgDispId[0] = DebugExternalInterface[iX].dwDispID;
  122. hr = NOERROR;
  123. break;
  124. }
  125. }
  126. // Set the disid's for the parameters
  127. if (cNames > 1)
  128. {
  129. // Set a DISPID for function parameters
  130. for (UINT i = 1; i < cNames ; i++)
  131. rgDispId[i] = DISPID_UNKNOWN;
  132. }
  133. return hr;
  134. }
  135. /////////////////////////////////////////////////////////////
  136. // CDebug::Invoke
  137. HRESULT CDebug::Invoke
  138. (
  139. DISPID dispidMember,
  140. REFIID riid,
  141. LCID lcid,
  142. WORD wFlags,
  143. DISPPARAMS* pdispparams,
  144. VARIANT* pvarResult,
  145. EXCEPINFO* pexcepinfo,
  146. UINT* puArgErr
  147. )
  148. {
  149. HRESULT hr = S_OK;
  150. switch(dispidMember)
  151. {
  152. case DISPID_DEBUG_TRACE:
  153. {
  154. if(pdispparams && &pdispparams[0].rgvarg[0])
  155. Trace(pdispparams[0].rgvarg[0].bstrVal);
  156. break;
  157. }
  158. case DISPID_DEBUG_ISMSDEBUGMODE:
  159. {
  160. if (pvarResult != NULL)
  161. {
  162. VariantInit(pvarResult);
  163. V_VT(pvarResult) = VT_BOOL;
  164. V_BOOL(pvarResult) = Bool2VarBool(m_fMsDebugMode);
  165. }
  166. break;
  167. }
  168. case DISPID_DEBUG_ISOEMDEBUGMODE:
  169. {
  170. if ( NULL != pdispparams
  171. && 0 < pdispparams->cArgs
  172. && pvarResult != NULL)
  173. {
  174. VariantInit(pvarResult);
  175. V_VT(pvarResult) = VT_BOOL;
  176. V_BOOL(pvarResult) = Bool2VarBool(m_fOemDebugMode);
  177. }
  178. break;
  179. }
  180. default:
  181. {
  182. hr = DISP_E_MEMBERNOTFOUND;
  183. break;
  184. }
  185. }
  186. return hr;
  187. }
  188. /////////////////////////////////////////////////////////////
  189. // CDebug::GetMsDebugMode
  190. BOOL
  191. CDebug::IsMsDebugMode( )
  192. {
  193. // Allow default MsDebugMode to be overridden by
  194. // HKLM\Software\Microsoft\Windows\CurrentVersion\Setup\OOBE\MsDebug
  195. //
  196. #ifdef DBG
  197. DWORD dwIsDebug = TRUE;
  198. #else
  199. DWORD dwIsDebug = FALSE;
  200. #endif
  201. HKEY hKey = NULL;
  202. DWORD dwSize = sizeof(DWORD);
  203. if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  204. OOBE_MAIN_REG_KEY,
  205. 0,
  206. KEY_QUERY_VALUE,
  207. &hKey) == ERROR_SUCCESS)
  208. {
  209. RegQueryValueEx(hKey,
  210. OOBE_MSDEBUG_REG_VAL,
  211. 0,
  212. NULL,
  213. (LPBYTE)&dwIsDebug,
  214. &dwSize);
  215. RegCloseKey(hKey);
  216. }
  217. return (BOOL) dwIsDebug;
  218. }