go-toast

Send toast notifications in Windows
Log | Files | Refs | README | LICENSE

procs.go (1102B)


      1 //go:build windows
      2 
      3 package wintoast
      4 
      5 import (
      6 	"unsafe"
      7 
      8 	"github.com/go-ole/go-ole"
      9 	"golang.org/x/sys/windows"
     10 )
     11 
     12 var (
     13 	// Define procs that go-ole doesn't provide. This is how we register our Go-implemented
     14 	// COM objects.
     15 	modcombase              = windows.NewLazySystemDLL("combase.dll")
     16 	procRegisterClassObject = modcombase.NewProc("CoRegisterClassObject")
     17 )
     18 
     19 // registerClassFactory teaches the Windows Runtime about our factory that can allocate
     20 // instances of our ActivationCallback.
     21 func registerClassFactory(factory *IClassFactory) error {
     22 	// cookie is used as a handle to this class. It is used when calling CoRevokeClassObject
     23 	// which unregisters the class. We don't need it until we plan to revoke this registration
     24 	// for some reason.
     25 	var cookie int64
     26 	hr, _, _ := procRegisterClassObject.Call(
     27 		uintptr(unsafe.Pointer(GUID_ImplNotificationActivationCallback)),
     28 		uintptr(unsafe.Pointer(factory)),
     29 		uintptr(ole.CLSCTX_LOCAL_SERVER),
     30 		uintptr(1), /* REGCLS_MULTIPLEUSE */
     31 		uintptr(unsafe.Pointer(&cookie)),
     32 	)
     33 	if hr != ole.S_OK {
     34 		return ole.NewError(hr)
     35 	}
     36 	return nil
     37 }