ErrorCode ComProxyXmlLiteWriter::Create(
    __in std::wstring const & outputName,
    __out ComProxyXmlLiteWriterUPtr & xmlLiteWriter, 
    bool writeByteOrderMark, 
    bool indent)
{
#if !defined(PLATFORM_UNIX)
    ComPointer<IStream> xmlFileStream;
    auto error = ComXmlFileStream::Open(outputName, true, xmlFileStream);
    if (!error.IsSuccess()) { return error; }

    ComPointer<IUnknown> comPointer;
    HRESULT hr = xmlFileStream->QueryInterface(IID_IUnknown, reinterpret_cast<void**>(comPointer.InitializationAddress()));
    if (!SUCCEEDED(hr)) { return ErrorCode::FromHResult(hr); }

    error = ComProxyXmlLiteWriter::Create(comPointer, xmlLiteWriter, writeByteOrderMark, indent);
    if (!error.IsSuccess()) { return error; }

#else
    ComPointer<IXmlWriter> writer;
    auto hr = ::CreateXmlWriter(
        ::IID_IXmlWriter, 
        outputName.c_str(),
        writer.VoidInitializationAddress(),
        NULL);
    auto error = ToErrorCode(hr, L"CreateXmlWriter", L"", true, false);
    if (!error.IsSuccess()) { return error; }

    xmlLiteWriter = move(make_unique<ComProxyXmlLiteWriter>(writer));
#endif

    return ErrorCode(ErrorCodeValue::Success);
}
ErrorCode ComProxyXmlLiteWriter::Create(
    ComPointer<IUnknown> const& output,
    __out ComProxyXmlLiteWriterUPtr & xmlLiteWriter,
    bool writeByteOrderMark,
    bool indent)
{
    ComPointer<IXmlWriter> writer;

#if !defined(PLATFORM_UNIX)
    auto hr = ::CreateXmlWriter(
        ::IID_IXmlWriter,
        writer.VoidInitializationAddress(),
        NULL);
#else
    auto hr = ::CreateMemoryXmlWriter(
        ::IID_IXmlWriter,
        output.GetRawPointer(),
        writer.VoidInitializationAddress(),
        NULL);
#endif

    auto error = ToErrorCode(hr, L"CreateXmlWriter", L"", true, false);
    if (!error.IsSuccess()) { return error; }

    if (writeByteOrderMark == false)
    {
        hr = writer->SetProperty(XmlWriterProperty_ByteOrderMark, FALSE);
        error = ToErrorCode(hr, L"SetProperty", L"", true, false);
        if (!error.IsSuccess()) { return error; }
    }
    if (indent)
    {
        hr = writer->SetProperty(XmlWriterProperty_Indent, TRUE);
        error = ToErrorCode(hr, L"SetProperty", L"", true, false);
        if (!error.IsSuccess()) { return error; }
    }

    xmlLiteWriter = move(make_unique<ComProxyXmlLiteWriter>(writer));

#if !defined(PLATFORM_UNIX)
    error = xmlLiteWriter->SetOutput(L"CustomOutput", output);
    if (!error.IsSuccess()) { return error; }
#endif

    return ErrorCode(ErrorCodeValue::Success);
}
HRESULT STDMETHODCALLTYPE ComServiceEndpointsVersion::Compare(
    __in /* [in] */ IFabricServiceEndpointsVersion * other,
    __out /* [out, retval] */ LONG * result)
{
    if (other == NULL || result == NULL) { return E_POINTER; }

    ComPointer<ComServiceEndpointsVersion> comPtr;
    auto hr = other->QueryInterface(CLSID_ComServiceEndpointsVersion, comPtr.VoidInitializationAddress());
    if (FAILED(hr)) { return hr; }

    *result = impl_->Compare(*(comPtr->get_Impl().get()));

    return S_OK;
}