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.

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