Implementing a component that sorts safearrays of variants.

The IDL file:

[
	uuid(6B71C6EA-0443-4137-9911-E1BDEBC89425),
	version(1.0)
]
library CometExampleSaSort
{
	importlib("stdole2.tlb");

	[
		uuid(AA4BC69C-A050-4cf4-9B27-E4AA67542A4A),
		dual
	]
	interface ISASort : IDispatch 
	{
		HRESULT Sort([in, out] SAFEARRAY(VARIANT)* array);
	}

	[
		uuid(91D97E5C-79EA-4f9a-80D9-1D0549951340)
	]
	coclass SASort
	{
		[default] interface ISASort;
	};		
	
};

The implementation of component SASort:

template<>
class coclass_implementation<SASort> : public coclass<SASort>
{
public:
    void Sort(safearray_t<variant_t>& sa)
	{
		std::sort(sa.begin(), sa.end());
	}
};

That's it - we're done!