Click here to Skip to main content
15,891,513 members
Articles / Desktop Programming / ATL

XML Transform Shell Extension

Rate me:
Please Sign up or sign in to vote.
4.08/5 (12 votes)
11 Oct 20033 min read 85.3K   1.6K   27  
A shell extension to transform xml files against a stylesheet
// xmlTransformerShlExt.h : Declaration of the CxmlTransformerShlExt

#pragma once
#include "resource.h"       // main symbols

#include "xmlTransformer.h"


// CxmlTransformerShlExt

class ATL_NO_VTABLE CxmlTransformerShlExt : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CxmlTransformerShlExt, &CLSID_xmlTransformerShlExt>,
    public IShellExtInit,
    public IContextMenu
{

private:

    CComBSTR bstrInputFile;
    TCHAR szTempFilePath[MAX_PATH];

    BOOL GetStyleSheet(TCHAR *filePath, UINT len);
    void ReportParseError(MSXML2::IXMLDOMParseErrorPtr pParseError, TCHAR *inputDoc);
    void WriteOutputAndDisplay(CComBSTR output);

public:
	CxmlTransformerShlExt()
	{
        // use the location of this dll to store the output file
        CRegKey regKey;
        DWORD len = MAX_PATH;

        regKey.Open( HKEY_CLASSES_ROOT, _T("CLSID\\{737E08D6-7EEA-4AD6-B15F-373B2BCDF5B7}\\InprocServer32"));
        regKey.QueryStringValue( _T(""), szTempFilePath, &len );
        regKey.Close();

        // fix the path
        PathRemoveFileSpec( szTempFilePath );
        PathAppend( szTempFilePath, _T("xmlTransformerOutput") );

	}

DECLARE_REGISTRY_RESOURCEID(IDR_XMLTRANSFORMERSHLEXT)


BEGIN_COM_MAP(CxmlTransformerShlExt)
    COM_INTERFACE_ENTRY(IShellExtInit)
    COM_INTERFACE_ENTRY(IContextMenu)
END_COM_MAP()


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
	}

public:
	// IShellExtInit
	STDMETHOD(Initialize)(LPCITEMIDLIST, LPDATAOBJECT, HKEY );

	// IContextMenu
	STDMETHOD(GetCommandString)(UINT, UINT, UINT*, LPSTR, UINT);
	STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO);
	STDMETHOD(QueryContextMenu)(HMENU, UINT, UINT, UINT, UINT );
};

OBJECT_ENTRY_AUTO(__uuidof(xmlTransformerShlExt), CxmlTransformerShlExt)

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