2024-02-15 17:14:06 -08:00

24 lines
728 B
Swift

import CWinRT
import WinSDK
public protocol CustomQueryInterface {
@_spi(WinRTImplements)
func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef?
}
extension IUnknownRef {
func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
var iid = iid
let (ptr) = try? ComPtrs.initialize(to: C_IUnknown.self) { result in
try CHECKED(borrow.pointee.lpVtbl.pointee.QueryInterface(borrow, &iid, &result))
}
guard let ptr else { return nil}
return IUnknownRef(ptr)
}
}
@_spi(WinRTInternal)
public func queryInterface(_ obj: WinRTClass, _ iid: WindowsFoundation.IID) -> IUnknownRef? {
obj._inner.pUnk.queryInterface(iid)
}