Created
November 17, 2024 02:06
-
-
Save hu13/4ce6e6f9019ff5c448071998128dac79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package provider | |
| import ( | |
| "fmt" | |
| "log" | |
| "testing" | |
| "unsafe" | |
| "github.com/saltosystems/winrt-go/windows/foundation/collections" | |
| "github.com/stretchr/testify/require" | |
| ) | |
| func Test_GetManyStorageProperyItem(t *testing.T) { | |
| prop1, err := NewStorageProviderItemProperty() | |
| require.NoError(t, err) | |
| prop1.SetId(1) | |
| prop1.SetValue("Value1") | |
| prop1.SetIconResource("shell32.dll,-44") | |
| prop2, err := NewStorageProviderItemProperty() | |
| require.NoError(t, err) | |
| prop2.SetId(2) | |
| prop2.SetValue("Value2") | |
| prop2.SetIconResource("shell32.dll,-44") | |
| log.Println("prop1", prop1) | |
| log.Println("prop2", prop2) | |
| a := collections.NewArrayIterable([]any{prop1, prop2}, SignatureStorageProviderItemProperty) | |
| it, err := a.First() | |
| require.NoError(t, err) | |
| resp, n, err := it.GetMany(3) // only 2 is available | |
| require.NoError(t, err) | |
| require.Equal(t, uint32(2), n) | |
| println("RESP", n, resp, len(resp)) | |
| // Extract and print the StorageProviderItemProperty objects | |
| for i := uint32(0); i < n; i++ { | |
| itemPtr := unsafe.Pointer(resp[i]) // Convert uintptr to pointer | |
| item := (*StorageProviderItemProperty)(itemPtr) // Cast pointer to StorageProviderItemProperty | |
| // Access properties of the StorageProviderItemProperty | |
| id, _ := item.GetId() | |
| value, _ := item.GetValue() | |
| iconResource, _ := item.GetIconResource() | |
| fmt.Printf("Item %d: Id=%d, Value=%s, IconResource=%s\n", i+1, id, value, iconResource) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Code generated by winrt-go-gen. DO NOT EDIT. | |
| //go:build windows | |
| //nolint:all | |
| package provider | |
| import ( | |
| "fmt" | |
| "syscall" | |
| "unsafe" | |
| "github.com/go-ole/go-ole" | |
| ) | |
| const SignatureStorageProviderItemProperty string = "rc(Windows.Storage.Provider.StorageProviderItemProperty;{476cb558-730b-4188-b7b5-63b716ed476d})" | |
| type StorageProviderItemProperty struct { | |
| ole.IUnknown | |
| } | |
| func NewStorageProviderItemProperty() (*StorageProviderItemProperty, error) { | |
| inspectable, err := ole.RoActivateInstance("Windows.Storage.Provider.StorageProviderItemProperty") | |
| if err != nil { | |
| return nil, err | |
| } | |
| return (*StorageProviderItemProperty)(unsafe.Pointer(inspectable)), nil | |
| } | |
| func (impl *StorageProviderItemProperty) SetId(value int32) error { | |
| itf := impl.MustQueryInterface(ole.NewGUID(GUIDiStorageProviderItemProperty)) | |
| defer itf.Release() | |
| v := (*iStorageProviderItemProperty)(unsafe.Pointer(itf)) | |
| return v.SetId(value) | |
| } | |
| func (impl *StorageProviderItemProperty) GetId() (int32, error) { | |
| itf := impl.MustQueryInterface(ole.NewGUID(GUIDiStorageProviderItemProperty)) | |
| defer itf.Release() | |
| fmt.Println("ggggg", itf) | |
| v := (*iStorageProviderItemProperty)(unsafe.Pointer(itf)) | |
| fmt.Println("get id", v) | |
| return v.GetId() | |
| } | |
| func (impl *StorageProviderItemProperty) SetValue(value string) error { | |
| itf := impl.MustQueryInterface(ole.NewGUID(GUIDiStorageProviderItemProperty)) | |
| defer itf.Release() | |
| v := (*iStorageProviderItemProperty)(unsafe.Pointer(itf)) | |
| return v.SetValue(value) | |
| } | |
| func (impl *StorageProviderItemProperty) GetValue() (string, error) { | |
| itf := impl.MustQueryInterface(ole.NewGUID(GUIDiStorageProviderItemProperty)) | |
| defer itf.Release() | |
| v := (*iStorageProviderItemProperty)(unsafe.Pointer(itf)) | |
| return v.GetValue() | |
| } | |
| func (impl *StorageProviderItemProperty) SetIconResource(value string) error { | |
| itf := impl.MustQueryInterface(ole.NewGUID(GUIDiStorageProviderItemProperty)) | |
| defer itf.Release() | |
| v := (*iStorageProviderItemProperty)(unsafe.Pointer(itf)) | |
| return v.SetIconResource(value) | |
| } | |
| func (impl *StorageProviderItemProperty) GetIconResource() (string, error) { | |
| itf := impl.MustQueryInterface(ole.NewGUID(GUIDiStorageProviderItemProperty)) | |
| defer itf.Release() | |
| v := (*iStorageProviderItemProperty)(unsafe.Pointer(itf)) | |
| return v.GetIconResource() | |
| } | |
| const GUIDiStorageProviderItemProperty string = "476cb558-730b-4188-b7b5-63b716ed476d" | |
| const SignatureiStorageProviderItemProperty string = "{476cb558-730b-4188-b7b5-63b716ed476d}" | |
| type iStorageProviderItemProperty struct { | |
| ole.IInspectable | |
| } | |
| type iStorageProviderItemPropertyVtbl struct { | |
| ole.IInspectableVtbl | |
| SetId uintptr | |
| GetId uintptr | |
| SetValue uintptr | |
| GetValue uintptr | |
| SetIconResource uintptr | |
| GetIconResource uintptr | |
| } | |
| func (v *iStorageProviderItemProperty) VTable() *iStorageProviderItemPropertyVtbl { | |
| return (*iStorageProviderItemPropertyVtbl)(unsafe.Pointer(v.RawVTable)) | |
| } | |
| func (v *iStorageProviderItemProperty) SetId(value int32) error { | |
| hr, _, _ := syscall.SyscallN( | |
| v.VTable().SetId, | |
| uintptr(unsafe.Pointer(v)), // this | |
| uintptr(value), // in int32 | |
| ) | |
| if hr != 0 { | |
| return ole.NewError(hr) | |
| } | |
| return nil | |
| } | |
| func (v *iStorageProviderItemProperty) GetId() (int32, error) { | |
| var out int32 | |
| hr, _, _ := syscall.SyscallN( | |
| v.VTable().GetId, | |
| uintptr(unsafe.Pointer(v)), // this | |
| uintptr(unsafe.Pointer(&out)), // out int32 | |
| ) | |
| if hr != 0 { | |
| return 0, ole.NewError(hr) | |
| } | |
| return out, nil | |
| } | |
| func (v *iStorageProviderItemProperty) SetValue(value string) error { | |
| valueHStr, err := ole.NewHString(value) | |
| if err != nil { | |
| return err | |
| } | |
| hr, _, _ := syscall.SyscallN( | |
| v.VTable().SetValue, | |
| uintptr(unsafe.Pointer(v)), // this | |
| uintptr(valueHStr), // in string | |
| ) | |
| if hr != 0 { | |
| return ole.NewError(hr) | |
| } | |
| return nil | |
| } | |
| func (v *iStorageProviderItemProperty) GetValue() (string, error) { | |
| var outHStr ole.HString | |
| hr, _, _ := syscall.SyscallN( | |
| v.VTable().GetValue, | |
| uintptr(unsafe.Pointer(v)), // this | |
| uintptr(unsafe.Pointer(&outHStr)), // out string | |
| ) | |
| if hr != 0 { | |
| return "", ole.NewError(hr) | |
| } | |
| out := outHStr.String() | |
| ole.DeleteHString(outHStr) | |
| return out, nil | |
| } | |
| func (v *iStorageProviderItemProperty) SetIconResource(value string) error { | |
| valueHStr, err := ole.NewHString(value) | |
| if err != nil { | |
| return err | |
| } | |
| hr, _, _ := syscall.SyscallN( | |
| v.VTable().SetIconResource, | |
| uintptr(unsafe.Pointer(v)), // this | |
| uintptr(valueHStr), // in string | |
| ) | |
| if hr != 0 { | |
| return ole.NewError(hr) | |
| } | |
| return nil | |
| } | |
| func (v *iStorageProviderItemProperty) GetIconResource() (string, error) { | |
| var outHStr ole.HString | |
| hr, _, _ := syscall.SyscallN( | |
| v.VTable().GetIconResource, | |
| uintptr(unsafe.Pointer(v)), // this | |
| uintptr(unsafe.Pointer(&outHStr)), // out string | |
| ) | |
| if hr != 0 { | |
| return "", ole.NewError(hr) | |
| } | |
| out := outHStr.String() | |
| ole.DeleteHString(outHStr) | |
| return out, nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment