ClearBox Server v1.2 Developer's Guide |
Step 9. Working With Extension PropertiesIn this step you will learn how server extension settings can be stored and configured by a user. Server extension must implement IPersistPropertyBag to take benefits of this approach. Server extension will use its configuration to read the path to the database it uses, and till this step it used hard-coded path. 1. Add line public IPersistPropertyBag to the list of classes CMyFirst inherits from. Find CMyFirst class definition, and its first lines should be class ATL_NO_VTABLE CMyFirst : public CComObjectRootEx<CComMultiThreadModel>, public CComCoClass<CMyFirst, &CLSID_MyFirst>, public ISupportErrorInfo, public IMyFirst, public ICommonExtender, public ICommonAuthentication, public IRADIUSAuthentication, public IRADIUSAccounting, public ITACACSAccounting, public IRADIUSAuthorization, public ITACACSAuthorization, public IPersistPropertyBag { Add line COM_INTERFACE_ENTRY(IPersistPropertyBag) to the interface map. 2. Add private CMyFirst member _bstr_t m_DBPath; It will store value read from extension configuration. 3. Add lines BEGIN_CATEGORY_MAP(CServerExtension) IMPLEMENTED_CATEGORY(CATID_TACRADServerExtension) END_CATEGORY_MAP() before interface map. These lines declare that server extension implements special COM category so Server Manager can find it within registered COM servers. Add directive #include "..\ext_category.h" after line #include "Database.h" 5. Add the following lines of code to the public part of CMyFirst class definition: STDMETHOD(Load)(IPropertyBag *pPropBag,IErrorLog *pErrorLog) { VARIANT var; VariantInit(&var); if (SUCCEEDED(pPropBag->Read(L"DB Path",&var,pErrorLog))) m_DBPath=_bstr_t(var.bstrVal,false); return S_OK; } STDMETHOD(Save)(IPropertyBag *pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties) { VARIANT var; VariantInit(&var); var.bstrVal=NULL; var.vt=VT_BSTR; pPropBag->Write(L"DB Path",&var); return S_OK; } STDMETHOD(GetClassID)(CLSID* pClsID) { return E_NOTIMPL; } STDMETHOD(InitNew)() { return E_NOTIMPL; } 6. Now server extension will make use of m_DBPath variable we have created. Find Initialize method in CMyFirst class. Replace constant file path with M_DBPath variable, and method declaration must look so now: STDMETHOD(Initialize)(VARIANT_BOOL start) { if (start==VARIANT_TRUE) { return m_DB.Open(m_DBPath); } else m_DB.Close(); return S_OK; } © 2001-2003 XPerience Technologies. www.xperiencetech.com |
Created by chm2web html help conversion utility. |