// Code generated by winrt-go-gen. DO NOT EDIT.

//go:build windows

//nolint:all
package dom

import (
	"syscall"
	"unsafe"

	"github.com/go-ole/go-ole"
)

const SignatureXmlDocument string = "rc(Windows.Data.Xml.Dom.XmlDocument;{f7f3a506-1e87-42d6-bcfb-b8c809fa5494})"

type XmlDocument struct {
	ole.IUnknown
}

func NewXmlDocument() (*XmlDocument, error) {
	inspectable, err := ole.RoActivateInstance("Windows.Data.Xml.Dom.XmlDocument")
	if err != nil {
		return nil, err
	}
	return (*XmlDocument)(unsafe.Pointer(inspectable)), nil
}

func (impl *XmlDocument) LoadXml(xml string) error {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiXmlDocumentIO))
	defer itf.Release()
	v := (*iXmlDocumentIO)(unsafe.Pointer(itf))
	return v.LoadXml(xml)
}

const (
	GUIDiXmlDocumentIO      string = "6cd0e74e-ee65-4489-9ebf-ca43e87ba637"
	SignatureiXmlDocumentIO string = "{6cd0e74e-ee65-4489-9ebf-ca43e87ba637}"
)

type iXmlDocumentIO struct {
	ole.IInspectable
}

type iXmlDocumentIOVtbl struct {
	ole.IInspectableVtbl

	LoadXml             uintptr
	LoadXmlWithSettings uintptr
	SaveToFileAsync     uintptr
}

func (v *iXmlDocumentIO) VTable() *iXmlDocumentIOVtbl {
	return (*iXmlDocumentIOVtbl)(unsafe.Pointer(v.RawVTable))
}

func (v *iXmlDocumentIO) LoadXml(xml string) error {
	xmlHStr, err := ole.NewHString(xml)
	if err != nil {
		return err
	}
	hr, _, _ := syscall.SyscallN(
		v.VTable().LoadXml,
		uintptr(unsafe.Pointer(v)), // this
		uintptr(xmlHStr),           // in string
	)

	if hr != 0 {
		return ole.NewError(hr)
	}

	return nil
}
