func FindMachine(nameOrId string) (Machine, error) {
  var machine Machine
  if err := Init(); err != nil {
    return machine, err
  }
  cnameOrId := C.CString(nameOrId)
  result := C.GoVboxFindMachine(cbox, cnameOrId, &machine.cmachine)
  C.free(unsafe.Pointer(cnameOrId))
  if C.GoVboxFAILED(result) != 0 || machine.cmachine == nil {
    return machine, errors.New(
        fmt.Sprintf("Failed to find IMachine: %x", result))
  }
  return machine, nil
}
FindMachine returns the VirtualBox machine with the given name.
It returns a new Machine instance and any error encountered.
package vbox
import "C"   
import (
  "errors"
  "fmt"
  "reflect"
  "unsafe"
)
type Machine struct {
  cmachine *C.IMachine
}
func (machine *Machine) GetName() (string, error) {
  var cname *C.char
  result := C.GoVboxGetMachineName(machine.cmachine, &cname)
  if C.GoVboxFAILED(result) != 0 || cname == nil {
    return "", errors.New(
        fmt.Sprintf("Failed to get IMachine name: %x", result))
  }
  name := C.GoString(cname)
  C.GoVboxUtf8Free(cname)
  return name, nil
}
func (machine *Machine) GetOsTypeId() (string, error) {
  var cosTypeId *C.char
  result := C.GoVboxGetMachineOSTypeId(machine.cmachine, &cosTypeId)
  if C.GoVboxFAILED(result) != 0 || cosTypeId == nil {
    return "", errors.New(
        fmt.Sprintf("Failed to get IMachine OS type ID: %x", result))
  }
  osTypeId := C.GoString(cosTypeId)
  C.GoVboxUtf8Free(cosTypeId)
  return osTypeId, nil
}
func (machine *Machine) GetSettingsFilePath() (string, error) {
  var cpath *C.char
  result := C.GoVboxGetMachineSettingsFilePath(machine.cmachine, &cpath)
  if C.GoVboxFAILED(result) != 0 || cpath == nil {
    return "", errors.New(
        fmt.Sprintf("Failed to get IMachine settings file path: %x", result))
  }
  path := C.GoString(cpath)
  C.GoVboxUtf8Free(cpath)
  return path, nil
}
func (machine *Machine) GetSettingsModified() (bool, error) {
  var cmodified C.PRBool
  result := C.GoVboxGetMachineSettingsModified(machine.cmachine, &cmodified)
  if C.GoVboxFAILED(result) != 0 {
    return false, errors.New(
        fmt.Sprintf("Failed to get IMachine modified flag: %x", result))
  }
  return cmodified != 0, nil
}
func (machine *Machine) SaveSettings() error {
  result := C.GoVboxMachineSaveSettings(machine.cmachine)
  if C.GoVboxFAILED(result) != 0 {
    return errors.New(
        fmt.Sprintf("Failed to save IMachine settings: %x", result))
  }
  return nil
}
func (machine* Machine) GetPointingHidType() (PointingHidType, error) {
  var ctype C.PRUint32
  result := C.GoVboxGetMachinePointingHIDType(machine.cmachine, &ctype)
  if C.GoVboxFAILED(result) != 0 {
    return 0, errors.New(
        fmt.Sprintf("Failed to get IMachine pointing HID type: %x", result))
  }
  return PointingHidType(ctype), nil
}
func (machine* Machine) SetPointingHidType(
    pointingHidType PointingHidType) error {
  result := C.GoVboxSetMachinePointingHIDType(machine.cmachine,
      C.PRUint32(pointingHidType))
  if C.GoVboxFAILED(result) != 0 {
    return errors.New(
        fmt.Sprintf("Failed to set IMachine pointing HID type: %x", result))
  }
  return nil
}
func (machine* Machine) GetMemorySize() (uint, error) {
  var cram C.PRUint32
  result := C.GoVboxGetMachineMemorySize(machine.cmachine, &cram)
  if C.GoVboxFAILED(result) != 0 {
    return 0, errors.New(
        fmt.Sprintf("Failed to get IMachine memory size: %x", result))
  }
  return uint(cram), nil
}
func (machine* Machine) SetMemorySize(ram uint) error {
  result := C.GoVboxSetMachineMemorySize(machine.cmachine, C.PRUint32(ram))
  if C.GoVboxFAILED(result) != 0 {
    return errors.New(
        fmt.Sprintf("Failed to set IMachine memory size: %x", result))
  }
  return nil
}
func (machine* Machine) GetVramSize() (uint, error) {
  var cvram C.PRUint32
  result := C.GoVboxGetMachineVRAMSize(machine.cmachine, &cvram)
  if C.GoVboxFAILED(result) != 0 {
    return 0, errors.New(
        fmt.Sprintf("Failed to get IMachine VRAM size: %x", result))
  }
  return uint(cvram), nil
}
func (machine* Machine) SetVramSize(vram uint) error {
  result := C.GoVboxSetMachineVRAMSize(machine.cmachine, C.PRUint32(vram))
  if C.GoVboxFAILED(result) != 0 {
    return errors.New(
        fmt.Sprintf("Failed to set IMachine VRAM size: %x", result))
  }
  return nil
}
func (machine *Machine) Register() error {
  result := C.GoVboxRegisterMachine(cbox, machine.cmachine)
  if C.GoVboxFAILED(result) != 0 {
    return errors.New(fmt.Sprintf("Failed to register IMachine: %x", result))
  }
  return nil
}
func (machine *Machine) Unregister(cleanupMode CleanupMode) ([]Medium, error) {
  var cmediaPtr **C.IMedium
  var mediaCount C.ULONG
  result := C.GoVboxMachineUnregister(machine.cmachine,
      C.PRUint32(cleanupMode), &cmediaPtr, &mediaCount)
  if C.GoVboxFAILED(result) != 0 || (cmediaPtr == nil && mediaCount != 0) {
    return nil, errors.New(
        fmt.Sprintf("Failed to unregister IMachine: %x", result))
  }
  sliceHeader := reflect.SliceHeader{
    Data: uintptr(unsafe.Pointer(cmediaPtr)),
    Len:  int(mediaCount),
    Cap:  int(mediaCount),
  }
  cmediaSlice := *(*[]*C.IMedium)(unsafe.Pointer(&sliceHeader))
  var media = make([]Medium, mediaCount)
  for i := range cmediaSlice {
    media[i] = Medium{cmediaSlice[i]}
  }
  C.GoVboxArrayOutFree(unsafe.Pointer(cmediaPtr))
  return media, nil
}
func (machine *Machine) DeleteConfig(media []Medium) (Progress, error) {
  var cmediaSlice []*C.IMedium
  var cmedia **C.IMedium
  if len(media) > 0 {
    cmediaSlice = make([]*C.IMedium, len(media))
    for i, medium := range media {
      cmediaSlice[i] = medium.cmedium
    }
    cmedia = &cmediaSlice[0]
  }
  var progress Progress
  result := C.GoVboxMachineDeleteConfig(machine.cmachine,
    C.PRUint32(len(media)), cmedia, &progress.cprogress)
  if C.GoVboxFAILED(result) != 0 || progress.cprogress == nil {
    return progress, errors.New(
        fmt.Sprintf("Failed to delete IMachine config: %x", result))
  }
  return progress, nil
}
func (machine *Machine) AttachDevice(controllerName string, controllerPort int,
    deviceSlot int, deviceType DeviceType, medium Medium) error {
  cname := C.CString(controllerName)
  result := C.GoVboxMachineAttachDevice(machine.cmachine, cname,
      C.PRInt32(controllerPort), C.PRInt32(deviceSlot), C.PRUint32(deviceType),
      medium.cmedium)
  C.free(unsafe.Pointer(cname))
  if C.GoVboxFAILED(result) != 0 {
    return errors.New(
        fmt.Sprintf("Failed to attach IMedium to IMachine: %x", result))
  }
  return nil
}
func (machine *Machine) UnmountMedium(controllerName string,
    controllerPort int, deviceSlot int, force bool) error {
  cforce := C.PRBool(0)
  if force {
    cforce = C.PRBool(1)
  }
  cname := C.CString(controllerName)
  result := C.GoVboxMachineUnmountMedium(machine.cmachine, cname,
      C.PRInt32(controllerPort), C.PRInt32(deviceSlot), cforce)
  C.free(unsafe.Pointer(cname))
  if C.GoVboxFAILED(result) != 0 {
    return errors.New(
        fmt.Sprintf("Failed to unmount medium from IMachine: %x", result))
  }
  return nil
}
func (machine *Machine) GetMedium(controllerName string, controllerPort int,
    deviceSlot int) (Medium, error) {
  var medium Medium
  cname := C.CString(controllerName)
  result := C.GoVboxMachineGetMedium(machine.cmachine, cname,
      C.PRInt32(controllerPort), C.PRInt32(deviceSlot), &medium.cmedium)
  C.free(unsafe.Pointer(cname))
  if C.GoVboxFAILED(result) != 0 || (medium.cmedium == nil) {
    return medium, errors.New(
        fmt.Sprintf("Failed to get IMedium from IMachine: %x", result))
  }
  return medium, nil
}
func (machine *Machine) Launch(session Session, uiType string,
    environment string) (Progress, error) {
  var progress Progress
  cuiType := C.CString(uiType)
  cenvironment := C.CString(environment)
  result := C.GoVboxMachineLaunchVMProcess(machine.cmachine, session.csession,
      cuiType, cenvironment, &progress.cprogress)
  C.free(unsafe.Pointer(cuiType))
  C.free(unsafe.Pointer(cenvironment))
  if C.GoVboxFAILED(result) != 0 || progress.cprogress == nil {
    return progress, errors.New(
        fmt.Sprintf("Failed to launch IMachine VM: %x", result))
  }
  return progress, nil
}
func (machine *Machine) Release() error {
  if machine.cmachine != nil {
    result := C.GoVboxIMachineRelease(machine.cmachine)
    if C.GoVboxFAILED(result) != 0 {
      return errors.New(fmt.Sprintf("Failed to release IMachine: %x", result))
    }
    machine.cmachine = nil
  }
  return nil
}
func (machine *Machine) Initialized() bool {
  return machine.cmachine != nil
}
func CreateMachine(
    name string, osTypeId string, flags string) (Machine, error) {
  var machine Machine
  if err := Init(); err != nil {
    return machine, err
  }
  cname := C.CString(name)
  cosTypeId := C.CString(osTypeId)
  cflags := C.CString(flags)
  result := C.GoVboxCreateMachine(cbox, cname, cosTypeId, cflags,
      &machine.cmachine)
  C.free(unsafe.Pointer(cname))
  C.free(unsafe.Pointer(cosTypeId))
  C.free(unsafe.Pointer(cflags))
  if C.GoVboxFAILED(result) != 0 || machine.cmachine == nil {
    return machine, errors.New(
        fmt.Sprintf("Failed to create IMachine: %x", result))
  }
  return machine, nil
}