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

//go:build windows

//nolint:all
package foundation

import (
	"syscall"
	"unsafe"

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

const GUIDIAsyncOperation string = "9fc2b0bb-e446-44e2-aa61-9cab8f636af2"
const SignatureIAsyncOperation string = "{9fc2b0bb-e446-44e2-aa61-9cab8f636af2}"

type IAsyncOperation struct {
	ole.IInspectable
}

type IAsyncOperationVtbl struct {
	ole.IInspectableVtbl

	SetCompleted uintptr
	GetCompleted uintptr
	GetResults   uintptr
}

func (v *IAsyncOperation) VTable() *IAsyncOperationVtbl {
	return (*IAsyncOperationVtbl)(unsafe.Pointer(v.RawVTable))
}

func (v *IAsyncOperation) SetCompleted(handler *AsyncOperationCompletedHandler) error {
	hr, _, _ := syscall.SyscallN(
		v.VTable().SetCompleted,
		uintptr(unsafe.Pointer(v)),       // this
		uintptr(unsafe.Pointer(handler)), // in AsyncOperationCompletedHandler
	)

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

	return nil
}

func (v *IAsyncOperation) GetCompleted() (*AsyncOperationCompletedHandler, error) {
	var out *AsyncOperationCompletedHandler
	hr, _, _ := syscall.SyscallN(
		v.VTable().GetCompleted,
		uintptr(unsafe.Pointer(v)),    // this
		uintptr(unsafe.Pointer(&out)), // out AsyncOperationCompletedHandler
	)

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

	return out, nil
}

func (v *IAsyncOperation) GetResults() (unsafe.Pointer, error) {
	var out unsafe.Pointer
	hr, _, _ := syscall.SyscallN(
		v.VTable().GetResults,
		uintptr(unsafe.Pointer(v)),    // this
		uintptr(unsafe.Pointer(&out)), // out unsafe.Pointer
	)

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

	return out, nil
}
