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.

201 lines
5.1 KiB

  1. #include "stdafx.h"
  2. #include <iadmw.h>
  3. #include <inetcom.h>
  4. #include <logtype.h>
  5. #include <ilogobj.hxx>
  6. #include "logui.h"
  7. #include "uincsa.h"
  8. #include "LogGenPg.h"
  9. #include "wrapmb.h"
  10. #include "logtools.h"
  11. #define OLE_NAME _T("NCSA_Logging_UI")
  12. static const DWORD BASED_CODE _dwOleMisc =
  13. OLEMISC_INSIDEOUT |
  14. OLEMISC_CANTLINKINSIDE;
  15. extern HINSTANCE g_hInstance;
  16. //====================== the required methods
  17. //---------------------------------------------------------------
  18. CFacNcsaLogUI::CFacNcsaLogUI() :
  19. COleObjectFactory( CLSID_NCSALOGUI, RUNTIME_CLASS(CNcsaCreator), TRUE, OLE_NAME )
  20. {
  21. }
  22. //---------------------------------------------------------------
  23. static const LPCTSTR rglpszServerRegister[] =
  24. {
  25. _T("%2\\CLSID\0") _T("%1"),
  26. _T("%2\\NotInsertable\0") _T(""),
  27. _T("%2\\protocol\\StdFileEditing\\verb\\0\0") _T("&Edit"),
  28. _T("CLSID\\%1\0") _T("%5"),
  29. _T("CLSID\\%1\\Verb\\0\0") _T("&Edit,0,2"),
  30. _T("CLSID\\%1\\NotInsertable\0") _T(""),
  31. _T("CLSID\\%1\\AuxUserType\\2\0") _T("%4"),
  32. _T("CLSID\\%1\\AuxUserType\\3\0") _T("%6"),
  33. _T("CLSID\\%1\\MiscStatus\0") _T("32"),
  34. NULL,
  35. };
  36. static const LPCTSTR rglpszServerOverwriteDLL[] =
  37. {
  38. _T("%2\\CLSID\0") _T("%1"),
  39. _T("%2\\protocol\\StdFileEditing\\server\0") _T("%3"),
  40. _T("CLSID\\%1\\ProgID\0") _T("%2"),
  41. _T("CLSID\\%1\\InProcServer32\0") _T("%3"),
  42. _T("CLSID\\%1\\DefaultIcon\0") _T("%3,%7"),
  43. NULL
  44. };
  45. BOOL CFacNcsaLogUI::UpdateRegistry( BOOL bRegister )
  46. {
  47. if (bRegister)
  48. /*
  49. return AfxOleRegisterControlClass(
  50. AfxGetInstanceHandle(),
  51. CLSID_NCSALOGUI,
  52. OLE_NAME,
  53. 0,
  54. 0,
  55. afxRegApartmentThreading,
  56. _dwOleMisc,
  57. _tlid,
  58. _wVerMajor,
  59. _wVerMinor);
  60. */
  61. if ( AfxOleRegisterServerClass(
  62. CLSID_NCSALOGUI,
  63. OLE_NAME,
  64. _T("LogUI ncsa"),
  65. _T("LogUI ncsa"),
  66. OAT_SERVER,
  67. (LPCTSTR *)rglpszServerRegister,
  68. (LPCTSTR *)rglpszServerOverwriteDLL
  69. ) )
  70. {
  71. return FSetObjectApartmentModel( CLSID_NCSALOGUI );
  72. }
  73. else
  74. return AfxOleUnregisterClass(m_clsid, OLE_NAME);
  75. return FALSE;
  76. }
  77. //---------------------------------------------------------------
  78. IMPLEMENT_DYNCREATE(CNcsaCreator, CCmdTarget)
  79. LPUNKNOWN CNcsaCreator::GetInterfaceHook(const void* piid)
  80. {
  81. return new CImpNcsaLogUI;
  82. }
  83. //====================== the action
  84. //---------------------------------------------------------------
  85. CImpNcsaLogUI::CImpNcsaLogUI():
  86. m_dwRefCount(0)
  87. {
  88. AfxOleLockApp();
  89. }
  90. //---------------------------------------------------------------
  91. CImpNcsaLogUI::~CImpNcsaLogUI()
  92. {
  93. AfxOleUnlockApp();
  94. }
  95. //---------------------------------------------------------------
  96. HRESULT CImpNcsaLogUI::OnProperties( IN OLECHAR* pocMachineName, IN OLECHAR* pocMetabasePath )
  97. {
  98. AFX_MANAGE_STATE(_afxModuleAddrThis);
  99. // prepare the metabase wrapper
  100. IMSAdminBase * pMB;
  101. if ( !FInitMetabaseWrapperEx( pocMachineName, &pMB ) )
  102. return 0xFFFFFFFF;
  103. // specify the resources to use
  104. HINSTANCE hOldRes = AfxGetResourceHandle();
  105. AfxSetResourceHandle( g_hInstance );
  106. // prepare the help
  107. ((CLoguiApp*)AfxGetApp())->PrepHelp( pocMetabasePath );
  108. // prepare the property sheet for action
  109. CLogGeneral pageLogGeneral;
  110. // declare the property sheet
  111. CPropertySheet propsheet( IDS_SHEET_NCSA_TITLE );
  112. // Things could (potentially maybe) throw here, so better protect it.
  113. try
  114. {
  115. // prepare the pages
  116. pageLogGeneral.m_pMB = pMB;
  117. pageLogGeneral.m_szMeta = pocMetabasePath;
  118. pageLogGeneral.m_szServer = pocMachineName;
  119. pageLogGeneral.szPrefix.LoadString( IDS_LOG_NCSA_PREFIX );
  120. pageLogGeneral.szSizePrefix.LoadString( IDS_LOG_SIZE_NCSA_PREFIX );
  121. // set the local flag
  122. pageLogGeneral.m_fLocalMachine = FIsLocalMachine( pocMachineName );
  123. // add the pages to the sheet and run
  124. propsheet.AddPage( &pageLogGeneral );
  125. // turn on help
  126. propsheet.m_psh.dwFlags |= PSH_HASHELP;
  127. pageLogGeneral.m_psp.dwFlags |= PSP_HASHELP;
  128. propsheet.DoModal();
  129. }
  130. catch ( CException e )
  131. {
  132. }
  133. // close the metabase wrappings
  134. FCloseMetabaseWrapperEx(&pMB);
  135. // restore the resources
  136. AfxSetResourceHandle( hOldRes );
  137. return NO_ERROR;
  138. }
  139. //====================== the required methods
  140. //---------------------------------------------------------------
  141. HRESULT CImpNcsaLogUI::QueryInterface(REFIID riid, void **ppObject)
  142. {
  143. if (riid==IID_IUnknown || riid==IID_LOGGINGUI || riid==CLSID_NCSALOGUI)
  144. {
  145. *ppObject = (ILogUIPlugin*) this;
  146. }
  147. else
  148. {
  149. return E_NOINTERFACE;
  150. }
  151. AddRef();
  152. return NO_ERROR;
  153. }
  154. //---------------------------------------------------------------
  155. ULONG CImpNcsaLogUI::AddRef()
  156. {
  157. DWORD dwRefCount;
  158. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  159. return dwRefCount;
  160. }
  161. //---------------------------------------------------------------
  162. ULONG CImpNcsaLogUI::Release()
  163. {
  164. DWORD dwRefCount;
  165. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  166. if (dwRefCount == 0) {
  167. delete this;
  168. }
  169. return dwRefCount;
  170. }