summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comctl_windows.go3
-rw-r--r--experiments/windowsconstgen.go38
-rw-r--r--zconstants_windows_386.go82
3 files changed, 121 insertions, 2 deletions
diff --git a/comctl_windows.go b/comctl_windows.go
index 6b61cef..2830e3c 100644
--- a/comctl_windows.go
+++ b/comctl_windows.go
@@ -59,7 +59,8 @@ func forceCommonControls6() (err error) {
actctx.lpSource = syscall.StringToUTF16Ptr(filename)
r1, _, err := _createActCtx.Call(uintptr(unsafe.Pointer(&actctx)))
- if r1 == negConst(_INVALID_HANDLE_VALUE) { // failure
+ // don't negConst() INVALID_HANDLE_VALUE; windowsconstgen was given a pointer by windows.h, and pointers are unsigned, so converting it back to signed doesn't work
+ if r1 == _INVALID_HANDLE_VALUE { // failure
return fmt.Errorf("error creating activation context for synthesized manifest file: %v", err)
}
r1, _, err = _activateActCtx.Call(
diff --git a/experiments/windowsconstgen.go b/experiments/windowsconstgen.go
index d9fd3bb..4671111 100644
--- a/experiments/windowsconstgen.go
+++ b/experiments/windowsconstgen.go
@@ -72,6 +72,31 @@ func gatherNames(pkg *ast.Package) {
}
}
+// some constants confuse cgo into thinking they're external symbols for some reason
+// TODO debug cgo
+var hacknames = map[string]string{
+ "_INVALID_HANDLE_VALUE": "x_INVALID_HANDLE_VALUE",
+}
+
+func hacknamesPreamble() string {
+ if len(hacknames) == 0 {
+ return ""
+ }
+ // keep sorted for git
+ hn := make([]string, 0, len(hacknames))
+ for origname, _ := range hacknames {
+ hn = append(hn, origname)
+ }
+ sort.Strings(hn)
+ s := "// /* because cgo has issues with these */\n"
+ s += "// #include <stdint.h>\n"
+ for _, origname := range hn {
+ s += "// uintptr_t " + hacknames[origname] + " = (uintptr_t) (" +
+ origname[1:] + ");\n" // strip leading _
+ }
+ return s
+}
+
func preamble(pkg string) string {
return "// autogenerated by windowsconstgen; do not edit\n" +
"package " + pkg + "\n"
@@ -104,6 +129,10 @@ func main() {
// keep sorted for git
consts := make([]string, 0, len(unknown))
for ident, _ := range unknown {
+ if hackname, ok := hacknames[ident]; ok {
+ consts = append(consts, hackname)
+ continue
+ }
consts = append(consts, ident)
}
sort.Strings(consts)
@@ -122,11 +151,18 @@ func main() {
"import \"fmt\"\n" +
"// #include <windows.h>\n" +
"// #include <commctrl.h>\n" +
+ "%s" +
"import \"C\"\n" +
"func main() {\n" +
" fmt.Println(%q)\n",
- preamble("main"), preamble("ui"))
+ preamble("main"), hacknamesPreamble(), preamble("ui"))
for _, ident := range consts {
+ if ident[0] == 'x' {
+ // hack name; strip the leading x (but not the _ after it) from the constant name but keep the value name unchanged
+ fmt.Fprintf(f, " fmt.Println(\"const %s =\", C.%s)\n", ident[1:], ident)
+ continue
+ }
+ // not a hack name; strip the leading _ from the value name but keep the constant name unchanged
fmt.Fprintf(f, " fmt.Println(\"const %s =\", C.%s)\n", ident, ident[1:])
}
fmt.Fprintf(f, "}\n")
diff --git a/zconstants_windows_386.go b/zconstants_windows_386.go
new file mode 100644
index 0000000..58144e1
--- /dev/null
+++ b/zconstants_windows_386.go
@@ -0,0 +1,82 @@
+// autogenerated by windowsconstgen; do not edit
+package ui
+
+const _BCM_GETIDEALSIZE = 5633
+const _BM_GETCHECK = 240
+const _BN_CLICKED = 0
+const _BST_CHECKED = 1
+const _BS_AUTOCHECKBOX = 3
+const _BS_PUSHBUTTON = 0
+const _CBS_AUTOHSCROLL = 64
+const _CBS_DROPDOWN = 2
+const _CBS_DROPDOWNLIST = 3
+const _CB_ADDSTRING = 323
+const _CB_DELETESTRING = 324
+const _CB_ERR = -1
+const _CB_ERRSPACE = -2
+const _CB_GETCOUNT = 326
+const _CB_GETCURSEL = 327
+const _CB_INSERTSTRING = 330
+const _COLOR_BTNFACE = 15
+const _CW_USEDEFAULT = -2147483648
+const _ERROR = 0
+const _ES_AUTOHSCROLL = 128
+const _ES_PASSWORD = 32
+const _GWL_STYLE = -16
+const _ICC_PROGRESS_CLASS = 32
+const _LBS_EXTENDEDSEL = 2048
+const _LBS_NOINTEGRALHEIGHT = 256
+const _LBS_NOTIFY = 1
+const _LB_ADDSTRING = 384
+const _LB_DELETESTRING = 386
+const _LB_ERR = -1
+const _LB_ERRSPACE = -2
+const _LB_GETCOUNT = 395
+const _LB_GETCURSEL = 392
+const _LB_GETSELCOUNT = 400
+const _LB_GETSELITEMS = 401
+const _LB_GETTEXT = 393
+const _LB_GETTEXTLEN = 394
+const _LB_INSERTSTRING = 385
+const _PBM_SETMARQUEE = 1034
+const _PBM_SETPOS = 1026
+const _PBS_MARQUEE = 8
+const _PBS_SMOOTH = 1
+const _SB_HORZ = 0
+const _SB_LEFT = 6
+const _SB_LINELEFT = 0
+const _SB_LINERIGHT = 1
+const _SB_PAGELEFT = 2
+const _SB_PAGERIGHT = 3
+const _SB_RIGHT = 7
+const _SB_THUMBPOSITION = 4
+const _SB_THUMBTRACK = 5
+const _SB_VERT = 1
+const _SIF_PAGE = 2
+const _SIF_POS = 4
+const _SIF_RANGE = 1
+const _SIF_TRACKPOS = 16
+const _SS_LEFTNOWORDWRAP = 12
+const _SS_NOPREFIX = 128
+const _SW_ERASE = 4
+const _SW_HIDE = 0
+const _SW_INVALIDATE = 2
+const _SW_SHOW = 5
+const _SW_SHOWDEFAULT = 10
+const _WM_CLOSE = 16
+const _WM_ERASEBKGND = 20
+const _WM_GETMINMAXINFO = 36
+const _WM_GETTEXT = 13
+const _WM_GETTEXTLENGTH = 14
+const _WM_HSCROLL = 276
+const _WM_SETFONT = 48
+const _WM_SIZE = 5
+const _WM_VSCROLL = 277
+const _WS_CHILD = 1073741824
+const _WS_EX_CLIENTEDGE = 512
+const _WS_HSCROLL = 1048576
+const _WS_OVERLAPPEDWINDOW = 13565952
+const _WS_TABSTOP = 65536
+const _WS_VISIBLE = 268435456
+const _WS_VSCROLL = 2097152
+const _INVALID_HANDLE_VALUE = 4294967295