github.com/gofiber/fiber/v2@v2.47.0/internal/go-ole/safearrayslices.go (about) 1 //go:build windows 2 // +build windows 3 4 package ole 5 6 import ( 7 "unsafe" 8 ) 9 10 func safeArrayFromByteSlice(slice []byte) *SafeArray { 11 array, _ := safeArrayCreateVector(VT_UI1, 0, uint32(len(slice))) 12 13 if array == nil { 14 panic("Could not convert []byte to SAFEARRAY") 15 } 16 17 for i, v := range slice { 18 safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(&v))) 19 } 20 return array 21 } 22 23 func safeArrayFromStringSlice(slice []string) *SafeArray { 24 array, _ := safeArrayCreateVector(VT_BSTR, 0, uint32(len(slice))) 25 26 if array == nil { 27 panic("Could not convert []string to SAFEARRAY") 28 } 29 // SysAllocStringLen(s) 30 for i, v := range slice { 31 safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(SysAllocStringLen(v)))) 32 } 33 return array 34 }