// Code generated by 'go generate'; DO NOT EDIT.

package enumerator

import (
	"syscall"
	"unsafe"

	"golang.org/x/sys/windows"
)

var _ unsafe.Pointer

// Do the interface allocations only once for common
// Errno values.
const (
	errnoERROR_IO_PENDING = 997
)

var (
	errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
	errERROR_EINVAL     error = syscall.EINVAL
)

// errnoErr returns common boxed Errno values, to prevent
// allocations at runtime.
func errnoErr(e syscall.Errno) error {
	switch e {
	case 0:
		return errERROR_EINVAL
	case errnoERROR_IO_PENDING:
		return errERROR_IO_PENDING
	}
	// TODO: add more here, after collecting data on the common
	// error values see on Windows. (perhaps when running
	// all.bat?)
	return e
}

var (
	modcfgmgr32 = windows.NewLazySystemDLL("cfgmgr32.dll")
	modsetupapi = windows.NewLazySystemDLL("setupapi.dll")

	procCM_Get_DevNode_Registry_PropertyW = modcfgmgr32.NewProc("CM_Get_DevNode_Registry_PropertyW")
	procCM_Get_Device_IDW                 = modcfgmgr32.NewProc("CM_Get_Device_IDW")
	procCM_Get_Device_ID_Size             = modcfgmgr32.NewProc("CM_Get_Device_ID_Size")
	procCM_Get_Parent                     = modcfgmgr32.NewProc("CM_Get_Parent")
	procCM_MapCrToWin32Err                = modcfgmgr32.NewProc("CM_MapCrToWin32Err")
	procSetupDiDestroyDeviceInfoList      = modsetupapi.NewProc("SetupDiDestroyDeviceInfoList")
	procSetupDiGetClassDevsW              = modsetupapi.NewProc("SetupDiGetClassDevsW")
	procSetupDiGetDeviceRegistryPropertyW = modsetupapi.NewProc("SetupDiGetDeviceRegistryPropertyW")
	procSetupDiOpenDevRegKey              = modsetupapi.NewProc("SetupDiOpenDevRegKey")
)

func cmGetDevNodeRegistryProperty(dev windows.DEVINST, property uint32, regDataType *uint32, buffer *byte, bufferLen *uint32, flags uint32) (cmErr cmError) {
	r0, _, _ := syscall.SyscallN(procCM_Get_DevNode_Registry_PropertyW.Addr(), uintptr(dev), uintptr(property), uintptr(unsafe.Pointer(regDataType)), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(bufferLen)), uintptr(flags))
	cmErr = cmError(r0)
	return
}

func cmGetDeviceID(dev windows.DEVINST, buffer unsafe.Pointer, bufferSize uint32, flags uint32) (err cmError) {
	r0, _, _ := syscall.SyscallN(procCM_Get_Device_IDW.Addr(), uintptr(dev), uintptr(buffer), uintptr(bufferSize), uintptr(flags))
	err = cmError(r0)
	return
}

func cmGetDeviceIDSize(outLen *uint32, dev windows.DEVINST, flags uint32) (cmErr cmError) {
	r0, _, _ := syscall.SyscallN(procCM_Get_Device_ID_Size.Addr(), uintptr(unsafe.Pointer(outLen)), uintptr(dev), uintptr(flags))
	cmErr = cmError(r0)
	return
}

func cmGetParent(outParentDev *windows.DEVINST, dev windows.DEVINST, flags uint32) (cmErr cmError) {
	r0, _, _ := syscall.SyscallN(procCM_Get_Parent.Addr(), uintptr(unsafe.Pointer(outParentDev)), uintptr(dev), uintptr(flags))
	cmErr = cmError(r0)
	return
}

func cmMapCrToWin32Err(cmErr cmError, defaultErr uint32) (err uint32) {
	r0, _, _ := syscall.SyscallN(procCM_MapCrToWin32Err.Addr(), uintptr(cmErr), uintptr(defaultErr))
	err = uint32(r0)
	return
}

func setupDiDestroyDeviceInfoList(set windows.DevInfo) (err error) {
	r1, _, e1 := syscall.SyscallN(procSetupDiDestroyDeviceInfoList.Addr(), uintptr(set))
	if r1 == 0 {
		err = errnoErr(e1)
	}
	return
}

func setupDiGetClassDevs(guid *windows.GUID, enumerator *string, hwndParent uintptr, flags windows.DIGCF) (set windows.DevInfo, err error) {
	r0, _, e1 := syscall.SyscallN(procSetupDiGetClassDevsW.Addr(), uintptr(unsafe.Pointer(guid)), uintptr(unsafe.Pointer(enumerator)), uintptr(hwndParent), uintptr(flags))
	set = windows.DevInfo(r0)
	if set == 0 {
		err = errnoErr(e1)
	}
	return
}

func setupDiGetDeviceRegistryProperty(set windows.DevInfo, devInfo *windows.DevInfoData, property windows.SPDRP, propertyType *uint32, outValue *byte, bufSize uint32, reqSize *uint32) (res bool) {
	r0, _, _ := syscall.SyscallN(procSetupDiGetDeviceRegistryPropertyW.Addr(), uintptr(set), uintptr(unsafe.Pointer(devInfo)), uintptr(property), uintptr(unsafe.Pointer(propertyType)), uintptr(unsafe.Pointer(outValue)), uintptr(bufSize), uintptr(unsafe.Pointer(reqSize)))
	res = r0 != 0
	return
}

func setupDiOpenDevRegKey(set windows.DevInfo, devInfo *windows.DevInfoData, scope windows.DICS_FLAG, hwProfile uint32, keyType windows.DIREG, samDesired uint32) (hkey syscall.Handle, err error) {
	r0, _, e1 := syscall.SyscallN(procSetupDiOpenDevRegKey.Addr(), uintptr(set), uintptr(unsafe.Pointer(devInfo)), uintptr(scope), uintptr(hwProfile), uintptr(keyType), uintptr(samDesired))
	hkey = syscall.Handle(r0)
	if hkey == 0 {
		err = errnoErr(e1)
	}
	return
}
