oleaut32.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2010-2012 The W32 Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build windows
  5. package w32
  6. import (
  7. "syscall"
  8. "unsafe"
  9. )
  10. var (
  11. modoleaut32 = syscall.NewLazyDLL("oleaut32")
  12. procVariantInit = modoleaut32.NewProc("VariantInit")
  13. procSysAllocString = modoleaut32.NewProc("SysAllocString")
  14. procSysFreeString = modoleaut32.NewProc("SysFreeString")
  15. procSysStringLen = modoleaut32.NewProc("SysStringLen")
  16. procCreateDispTypeInfo = modoleaut32.NewProc("CreateDispTypeInfo")
  17. procCreateStdDispatch = modoleaut32.NewProc("CreateStdDispatch")
  18. )
  19. func VariantInit(v *VARIANT) {
  20. hr, _, _ := procVariantInit.Call(uintptr(unsafe.Pointer(v)))
  21. if hr != 0 {
  22. panic("Invoke VariantInit error.")
  23. }
  24. return
  25. }
  26. func SysAllocString(v string) (ss *int16) {
  27. pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v))))
  28. ss = (*int16)(unsafe.Pointer(pss))
  29. return
  30. }
  31. func SysFreeString(v *int16) {
  32. hr, _, _ := procSysFreeString.Call(uintptr(unsafe.Pointer(v)))
  33. if hr != 0 {
  34. panic("Invoke SysFreeString error.")
  35. }
  36. return
  37. }
  38. func SysStringLen(v *int16) uint {
  39. l, _, _ := procSysStringLen.Call(uintptr(unsafe.Pointer(v)))
  40. return uint(l)
  41. }