-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
x/sys/windows doesn't have a mod version, so maybe there's some leeway for breaking stuff. Here's the mischief I have in mind:
All functions that take strings in x/sys/windows take a *uint16. It's then up to the caller to do the rather cumbersome:
//sys DoWithFooBar(foo *uint16, bar *uint16) = user32.DoWithFooBarW
foo16, err := windows.UTF16PtrFromString(foo)
if err != nil {
return err
}
bar16, err := windows.UTF16PtrFromString(bar)
if err != nil {
return err
}
return windows.DoWithFooBar(foo16, bar16)
When you have lots of strings, this is really a drag.
As it turns out, mksyscall.go will automatically generate the conversion. So instead these work:
//sys DoWithFooBar(foo string, bar string) = user32.DoWithFooBarW
return windows.DoWithFooBar(foo, bar)
Under the hood, the generated bindings do the right thing.
Now to be clear, I'm not proposing that we change mksyscall.go to generate the string conversion code. Why? Because this is already implemented!
What I am suggesting is that we change all of the definitions in x/sys/windows to take a simple string type instead of forcing the user to muck with *uint16. I assume that the conversion code was added to mksyscall.go for this reason, but then for some reason it never made it to x/sys/windows.