internal/ui: bug fix: care the case when CoInitializeEx returns S_FALSE

This commit is contained in:
Hajime Hoshi 2022-12-13 13:01:32 +09:00
parent 8ab220df7f
commit 72dc730b42

View File

@ -20,6 +20,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"runtime" "runtime"
"syscall"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
@ -187,9 +188,11 @@ func initializeWindowAfterCreation(w *glfw.Window) {
} }
func (u *userInterfaceImpl) skipTaskbar() error { func (u *userInterfaceImpl) skipTaskbar() error {
if err := windows.CoInitializeEx(0, windows.COINIT_MULTITHREADED); err != nil { // S_FALSE is returned when CoInitializeEx is nested. This is a successful case.
if err := windows.CoInitializeEx(0, windows.COINIT_MULTITHREADED); err != nil && !errors.Is(err, syscall.Errno(windows.S_FALSE)) {
return err return err
} }
// CoUninitialize should be called even when CoInitializeEx returns S_FALSE.
defer windows.CoUninitialize() defer windows.CoUninitialize()
ptr, err := _CoCreateInstance(&_CLSID_TaskbarList, nil, _CLSCTX_SERVER, &_IID_ITaskbarList) ptr, err := _CoCreateInstance(&_CLSID_TaskbarList, nil, _CLSCTX_SERVER, &_IID_ITaskbarList)