zenity/internal/win/ole32.go

70 lines
2.1 KiB
Go
Raw Normal View History

2022-06-17 22:45:49 -04:00
//go:build windows
package win
import (
2022-06-21 19:58:14 -04:00
"reflect"
2022-06-17 22:45:49 -04:00
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
const (
2022-06-19 21:14:08 -04:00
COINIT_MULTITHREADED = windows.COINIT_MULTITHREADED
COINIT_APARTMENTTHREADED = windows.COINIT_APARTMENTTHREADED
COINIT_DISABLE_OLE1DDE = windows.COINIT_DISABLE_OLE1DDE
COINIT_SPEED_OVER_MEMORY = windows.COINIT_SPEED_OVER_MEMORY
CLSCTX_INPROC_SERVER = windows.CLSCTX_INPROC_SERVER
CLSCTX_INPROC_HANDLER = windows.CLSCTX_INPROC_HANDLER
CLSCTX_LOCAL_SERVER = windows.CLSCTX_LOCAL_SERVER
CLSCTX_REMOTE_SERVER = windows.CLSCTX_REMOTE_SERVER
CLSCTX_ALL = windows.CLSCTX_INPROC_SERVER | windows.CLSCTX_INPROC_HANDLER | windows.CLSCTX_LOCAL_SERVER | windows.CLSCTX_REMOTE_SERVER
E_CANCELED = windows.ERROR_CANCELLED | windows.FACILITY_WIN32<<16 | 0x80000000
RPC_E_CHANGED_MODE = syscall.Errno(windows.RPC_E_CHANGED_MODE)
2022-06-17 22:45:49 -04:00
)
func CoInitializeEx(reserved uintptr, coInit uint32) error {
return windows.CoInitializeEx(reserved, coInit)
}
func CoUninitialize() { windows.CoUninitialize() }
2022-06-22 10:14:52 -04:00
func CoTaskMemFree(address unsafe.Pointer) { windows.CoTaskMemFree(address) }
2022-06-17 22:45:49 -04:00
// https://github.com/wine-mirror/wine/blob/master/include/unknwn.idl
2022-06-22 10:14:52 -04:00
type IUnknown struct{}
type iUnknownVtbl struct {
2022-06-17 22:45:49 -04:00
QueryInterface uintptr
AddRef uintptr
Release uintptr
}
2022-06-22 10:14:52 -04:00
func (u *IUnknown) Release() {
vtbl := *(**iUnknownVtbl)(unsafe.Pointer(u))
u.call(vtbl.Release)
2022-06-21 19:58:14 -04:00
}
2022-06-17 22:45:49 -04:00
//go:uintptrescapes
2022-06-22 10:14:52 -04:00
func (u *IUnknown) call(trap uintptr, a ...uintptr) (r1, r2 uintptr, lastErr error) {
2022-08-10 18:52:39 -04:00
return unkcall(uintptr(unsafe.Pointer(u)), trap, a...)
}
//go:uintptrescapes
func unkcall(self, trap uintptr, a ...uintptr) (r1, r2 uintptr, lastErr error) {
return syscall.SyscallN(trap, append([]uintptr{self}, a...)...)
2022-06-17 22:45:49 -04:00
}
2022-06-22 10:14:52 -04:00
// https://github.com/wine-mirror/wine/blob/master/include/objidl.idl
type IBindCtx struct{ IUnknown }
2022-11-02 06:21:31 -04:00
//sys CoCreateInstance(clsid *GUID, unkOuter *IUnknown, clsContext int32, iid *GUID, address unsafe.Pointer) (res error) = ole32.CoCreateInstance
2022-06-21 19:58:14 -04:00
2022-11-02 06:21:31 -04:00
func guid(s string) *GUID {
return (*GUID)(unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&s)).Data))
2022-06-21 19:58:14 -04:00
}