Skip to content

Commit 0e05c5c

Browse files
committed
CoCreateGuid function.
1 parent 282334c commit 0e05c5c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

internal/proc/ole32.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var (
1010
ole32 = syscall.NewLazyDLL("ole32.dll")
1111

1212
CLSIDFromProgID = ole32.NewProc("CLSIDFromProgID")
13+
CoCreateGuid = ole32.NewProc("CoCreateGuid")
1314
CoCreateInstance = ole32.NewProc("CoCreateInstance")
1415
CoInitializeEx = ole32.NewProc("CoInitializeEx")
1516
CoTaskMemAlloc = ole32.NewProc("CoTaskMemAlloc")

win/com/com/any_funcs.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ func CLSIDFromProgID(progId string) (co.CLSID, error) {
4444
}
4545
}
4646

47+
// [CoCreateGuid] function.
48+
//
49+
// This function creates a globally unique 128-bit integer.
50+
//
51+
// [CoCreateGuid]: https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-cocreateguid
52+
func CoCreateGuid() win.GUID {
53+
var guid win.GUID
54+
ret, _, _ := syscall.SyscallN(proc.CoCreateGuid.Addr(),
55+
uintptr(unsafe.Pointer(&guid)))
56+
if hr := errco.ERROR(ret); hr == errco.S_OK {
57+
return guid
58+
} else {
59+
panic(hr)
60+
}
61+
}
62+
4763
// [CoCreateInstance] function.
4864
//
4965
// Creates a COM object from its CLSID + IID. The iUnkOuter is usually nil.

0 commit comments

Comments
 (0)