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