func (obj *Direct3D) CreateDevice(
	adapter uint,
	deviceType DEVTYPE,
	focusWindow HWND,
	behaviorFlags uint32,
	params PRESENT_PARAMETERS,
) (*Device, PRESENT_PARAMETERS, Error) {
	var device *Device
	ret, _, _ := syscall.Syscall9(
		obj.vtbl.CreateDevice,
		7,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(focusWindow),
		uintptr(behaviorFlags),
		uintptr(unsafe.Pointer(&params)),
		uintptr(unsafe.Pointer(&device)),
		0,
		0,
	)
	return device, params, toErr(ret)
}
CreateDevice creates a device to represent the display adapter.
package d3d9
import (
	"errors"
	"syscall"
	"unsafe"
)
var (
	dll             = syscall.NewLazyDLL("d3d9.dll")
	direct3DCreate9 = dll.NewProc("Direct3DCreate9")
)
func Create(version uint) (*Direct3D, error) {
	obj, _, _ := direct3DCreate9.Call(uintptr(version))
	if obj == 0 {
		return nil, errors.New("Direct3DCreate9 returned nil")
	}
	return (*Direct3D)(unsafe.Pointer(obj)), nil
}
type Direct3D struct {
	vtbl *direct3DVtbl
}
type direct3DVtbl struct {
	QueryInterface uintptr
	AddRef         uintptr
	Release        uintptr
	RegisterSoftwareDevice      uintptr
	GetAdapterCount             uintptr
	GetAdapterIdentifier        uintptr
	GetAdapterModeCount         uintptr
	EnumAdapterModes            uintptr
	GetAdapterDisplayMode       uintptr
	CheckDeviceType             uintptr
	CheckDeviceFormat           uintptr
	CheckDeviceMultiSampleType  uintptr
	CheckDepthStencilMatch      uintptr
	CheckDeviceFormatConversion uintptr
	GetDeviceCaps               uintptr
	GetAdapterMonitor           uintptr
	CreateDevice                uintptr
}
func (obj *Direct3D) AddRef() uint32 {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.AddRef,
		1,
		uintptr(unsafe.Pointer(obj)),
		0,
		0,
	)
	return uint32(ret)
}
func (obj *Direct3D) Release() uint32 {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.Release,
		1,
		uintptr(unsafe.Pointer(obj)),
		0,
		0,
	)
	return uint32(ret)
}
func (obj *Direct3D) RegisterSoftwareDevice(initFunc uintptr) Error {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.RegisterSoftwareDevice,
		2,
		uintptr(unsafe.Pointer(obj)),
		initFunc,
		0,
	)
	return toErr(ret)
}
func (obj *Direct3D) GetAdapterCount() uint {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.GetAdapterCount,
		1,
		uintptr(unsafe.Pointer(obj)),
		0,
		0,
	)
	return uint(ret)
}
func (obj *Direct3D) GetAdapterIdentifier(
	adapter uint,
	flags uint32,
) (id ADAPTER_IDENTIFIER, err Error) {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.GetAdapterIdentifier,
		4,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(flags),
		uintptr(unsafe.Pointer(&id)),
		0,
		0,
	)
	err = toErr(ret)
	return
}
func (obj *Direct3D) GetAdapterModeCount(adapter uint, format FORMAT) uint {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.GetAdapterModeCount,
		3,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(format),
	)
	return uint(ret)
}
func (obj *Direct3D) EnumAdapterModes(
	adapter uint,
	format FORMAT,
	mode uint,
) (displayMode DISPLAYMODE, err Error) {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.EnumAdapterModes,
		5,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(format),
		uintptr(mode),
		uintptr(unsafe.Pointer(&displayMode)),
		0,
	)
	err = toErr(ret)
	return
}
func (obj *Direct3D) GetAdapterDisplayMode(
	adapter uint,
) (mode DISPLAYMODE, err Error) {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.GetAdapterDisplayMode,
		3,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(unsafe.Pointer(&mode)),
	)
	err = toErr(ret)
	return
}
func (obj *Direct3D) CheckDeviceType(
	adapter uint,
	deviceType DEVTYPE,
	displayFormat FORMAT,
	backBufferFormat FORMAT,
	windowed bool,
) Error {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.CheckDeviceType,
		6,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(displayFormat),
		uintptr(backBufferFormat),
		uintptrBool(windowed),
	)
	return toErr(ret)
}
func uintptrBool(b bool) uintptr {
	if b {
		return 1
	}
	return 0
}
func (obj *Direct3D) CheckDeviceFormat(
	adapter uint,
	deviceType DEVTYPE,
	adapterFormat FORMAT,
	usage uint32,
	resType RESOURCETYPE,
	checkFormat FORMAT,
) Error {
	ret, _, _ := syscall.Syscall9(
		obj.vtbl.CheckDeviceFormat,
		7,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(adapterFormat),
		uintptr(usage),
		uintptr(resType),
		uintptr(checkFormat),
		0,
		0,
	)
	return toErr(ret)
}
func (obj *Direct3D) CheckDeviceMultiSampleType(
	adapter uint,
	deviceType DEVTYPE,
	surfaceFormat FORMAT,
	windowed bool,
	multiSampleType MULTISAMPLE_TYPE,
) (qualityLevels uint32, err Error) {
	ret, _, _ := syscall.Syscall9(
		obj.vtbl.CheckDeviceMultiSampleType,
		7,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(surfaceFormat),
		uintptrBool(windowed),
		uintptr(multiSampleType),
		uintptr(unsafe.Pointer(&qualityLevels)),
		0,
		0,
	)
	err = toErr(ret)
	return
}
func (obj *Direct3D) CheckDepthStencilMatch(
	adapter uint,
	deviceType DEVTYPE,
	adapterFormat FORMAT,
	renderTargetFormat FORMAT,
	depthStencilFormat FORMAT,
) Error {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.CheckDepthStencilMatch,
		6,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(adapterFormat),
		uintptr(renderTargetFormat),
		uintptr(depthStencilFormat),
	)
	return toErr(ret)
}
func (obj *Direct3D) CheckDeviceFormatConversion(
	adapter uint,
	deviceType DEVTYPE,
	sourceFormat FORMAT,
	targetFormat FORMAT,
) Error {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.CheckDeviceFormatConversion,
		5,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(sourceFormat),
		uintptr(targetFormat),
		0,
	)
	return toErr(ret)
}
func (obj *Direct3D) GetDeviceCaps(
	adapter uint,
	deviceType DEVTYPE,
) (caps CAPS, err Error) {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.GetDeviceCaps,
		4,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(unsafe.Pointer(&caps)),
		0,
		0,
	)
	err = toErr(ret)
	return
}
func (obj *Direct3D) GetAdapterMonitor(adapter uint) HMONITOR {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.GetAdapterMonitor,
		2,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		0,
	)
	return HMONITOR(ret)
}