zenity/internal/win/ole32.go

65 lines
1.9 KiB
Go
Raw Permalink 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-12-02 10:11:48 -05:00
return syscall.SyscallN(trap, append([]uintptr{uintptr(unsafe.Pointer(u))}, 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
}