Click here to Skip to main content
15,894,546 members
Articles / Desktop Programming / ATL

ATL PersistXML implementation

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
28 Jul 20032 min read 127.2K   1.3K   38  
Easiest way to add XML persistence to an existing IDispatch based ATL COM object.
// CSystemUser.h : Declaration of the CSystemUser

/////////////////////////////////////////////////////
//											
// This is a part of the ATL PersistXML add-on
// 
// Copyright (c) VitalyKatasonov.  All rights reserved.
//
// free to use everywhere!
//
// any comments send to:  vkatasonov@yahoo.com
//
/////////////////////////////////////////////////////

#ifndef __SYSTEMUSER_H_
#define __SYSTEMUSER_H_

#include "resource.h"       // main symbols
#include "..\PersistVarXml\IPersistVarXMLImpl.h"
#include "CMySystem.h"


/////////////////////////////////////////////////////////////////////////////
// CSystemUser
class ATL_NO_VTABLE CSystemUser : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CSystemUser, &CLSID_SystemUser>,
	public IDispatchImpl<ISystemUser, &IID_ISystemUser, &LIBID_MYOBJECTSLib>,
	public IPersistVarXMLImpl<CSystemUser>
{
public:
	DECLARE_XML_ELEMENT_NAME(USER)

	CSystemUser():m_bstrName("Unknown")
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_SYSTEMUSER)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CSystemUser)
	COM_INTERFACE_ENTRY(ISystemUser)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISAXContentHandler)
	COM_INTERFACE_ENTRY(IPersistVarXML)
END_COM_MAP()



BEGIN_PROP_MAP(CSystemUser)
	PROP_ENTRY_EX( "Name",			1,		CLSID_NULL,IID_ISystemUser )
	PROP_ENTRY_EX( "Address",		2,		CLSID_NULL,IID_ISystemUser )
END_PROP_MAP()


//IEDPersistXML
BEGIN_XML_CONTENT_MAP(CSystemUser)
	XML_CONTENT_ENTRY(&m_objSystem)
END_XML_CONTENT_MAP()

	unsigned m_bRequiresSave:1;


// ISystemUser
public:
	STDMETHOD(get_TreeItem)(/*[out, retval]*/ long *pVal);
	STDMETHOD(put_TreeItem)(/*[in]*/ long newVal);
	STDMETHOD(get_System)(/*[out, retval]*/ LPDISPATCH *pVal);
	STDMETHOD(get_Address)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put_Address)(/*[in]*/ BSTR newVal);
	STDMETHOD(get_Name)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put_Name)(/*[in]*/ BSTR newVal);

	CComBSTR	m_bstrName;
	CComBSTR	m_bstrAddress;

	CComObjectGlobal<CMySystem>	m_objSystem;
	long m_lTreeItem;

};

#endif //__SYSTEMUSER_H_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions