5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 07:41:37 +08:00
wails/v2/internal/frontend/desktop/windows/go-webview2/pkg/combridge/syscall.go
stffabi 0a20c8db96
[webview2loader] Add full featured go implementation (#1974)
* [webview2loader] Add full featured go implementation

The new go loader can be activated with the exp_gowebview2loader build tag.

* [build] Add information for using the new webvie2loader
2022-10-22 00:29:16 +11:00

38 lines
757 B
Go

package combridge
import (
"unsafe"
"golang.org/x/sys/windows"
)
var (
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
procGlobalAlloc = modkernel32.NewProc("GlobalAlloc")
procGlobalFree = modkernel32.NewProc("GlobalFree")
uintptrSize = unsafe.Sizeof(uintptr(0))
)
func allocUintptrObject(size int) (uintptr, []uintptr) {
v := globalAlloc(uintptr(size) * uintptrSize)
slice := unsafe.Slice((*uintptr)(unsafe.Pointer(v)), size)
return v, slice
}
func globalAlloc(dwBytes uintptr) uintptr {
ret, _, _ := procGlobalAlloc.Call(uintptr(0), dwBytes)
if ret == 0 {
panic("globalAlloc failed")
}
return ret
}
func globalFree(data uintptr) {
ret, _, _ := procGlobalFree.Call(data)
if ret != 0 {
panic("globalFree failed")
}
}