-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose ICreateErrorInfo + CreateErrorInfo and use it for creating IEr…
…rorInfo objects.
- Loading branch information
1 parent
571f96f
commit 1972cc0
Showing
6 changed files
with
123 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import COM_ABI | ||
|
||
public typealias ICreateErrorInfo = any ICreateErrorInfoProtocol | ||
public protocol ICreateErrorInfoProtocol: IUnknownProtocol { | ||
func setGUID(_ guid: GUID) throws | ||
func setSource(_ source: String?) throws | ||
func setDescription(_ description: String?) throws | ||
func setHelpFile(_ helpFile: String?) throws | ||
func setHelpContext(_ helpContext: UInt32) throws | ||
} | ||
|
||
public enum ICreateErrorInfoProjection: COMTwoWayProjection { | ||
public typealias ABIStruct = COM_ABI.SWRT_ICreateErrorInfo | ||
public typealias SwiftObject = ICreateErrorInfo | ||
|
||
public static var interfaceID: COMInterfaceID { uuidof(ABIStruct.self) } | ||
public static var virtualTablePointer: UnsafeRawPointer { .init(withUnsafePointer(to: &virtualTable) { $0 }) } | ||
|
||
public static func _wrap(_ reference: consuming ABIReference) -> SwiftObject { | ||
Import(_wrapping: reference) | ||
} | ||
|
||
public static func toCOM(_ object: SwiftObject) throws -> ABIReference { | ||
try Import.toCOM(object) | ||
} | ||
|
||
private final class Import: COMImport<ICreateErrorInfoProjection>, ICreateErrorInfoProtocol { | ||
public func setGUID(_ guid: GUID) throws { try _interop.setGUID(guid) } | ||
public func setSource(_ source: String?) throws { try _interop.setSource(source) } | ||
public func setDescription(_ description: String?) throws { try _interop.setDescription(description) } | ||
public func setHelpFile(_ helpFile: String?) throws { try _interop.setHelpFile(helpFile) } | ||
public func setHelpContext(_ helpContext: UInt32) throws { try _interop.setHelpContext(helpContext) } | ||
} | ||
|
||
private static var virtualTable: COM_ABI.SWRT_ICreateErrorInfo_VirtualTable = .init( | ||
QueryInterface: { IUnknownVirtualTable.QueryInterface($0, $1, $2) }, | ||
AddRef: { IUnknownVirtualTable.AddRef($0) }, | ||
Release: { IUnknownVirtualTable.Release($0) }, | ||
SetGUID: { this, guid in _implement(this) { | ||
guard let guid else { throw COMError.invalidArg } | ||
try $0.setGUID(GUIDProjection.toSwift(guid.pointee)) | ||
} }, | ||
SetSource: { this, source in _implement(this) { try $0.setSource(BStrProjection.toSwift(source)) } }, | ||
SetDescription: { this, description in _implement(this) { try $0.setDescription(BStrProjection.toSwift(description)) } }, | ||
SetHelpFile: { this, helpFile in _implement(this) { try $0.setHelpFile(BStrProjection.toSwift(helpFile)) } }, | ||
SetHelpContext: { this, helpContext in _implement(this) { try $0.setHelpContext(helpContext) } }) | ||
} | ||
|
||
public func uuidof(_: COM_ABI.SWRT_ICreateErrorInfo.Type) -> COMInterfaceID { | ||
.init(0x22F03340, 0x547D, 0x101B, 0x8E65, 0x08002B2BD119) | ||
} | ||
|
||
extension COMInterop where ABIStruct == COM_ABI.SWRT_ICreateErrorInfo { | ||
public func setGUID(_ guid: GUID) throws { | ||
var guid = GUIDProjection.toABI(guid) | ||
try COMError.fromABI(this.pointee.VirtualTable.pointee.SetGUID(this, &guid)) | ||
} | ||
|
||
public func setSource(_ source: String?) throws { | ||
var source = try BStrProjection.toABI(source) | ||
defer { BStrProjection.release(&source) } | ||
try COMError.fromABI(this.pointee.VirtualTable.pointee.SetSource(this, source)) | ||
} | ||
|
||
public func setDescription(_ description: String?) throws { | ||
var description = try BStrProjection.toABI(description) | ||
defer { BStrProjection.release(&description) } | ||
try COMError.fromABI(this.pointee.VirtualTable.pointee.SetDescription(this, description)) | ||
} | ||
|
||
public func setHelpFile(_ helpFile: String?) throws { | ||
var helpFile = try BStrProjection.toABI(helpFile) | ||
defer { BStrProjection.release(&helpFile) } | ||
try COMError.fromABI(this.pointee.VirtualTable.pointee.SetHelpFile(this, helpFile)) | ||
} | ||
|
||
public func setHelpContext(_ helpContext: UInt32) throws { | ||
try COMError.fromABI(this.pointee.VirtualTable.pointee.SetHelpContext(this, helpContext)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import COM_ABI | ||
|
||
/// Creates an instance of `ICreateErrorInfo`. | ||
public func createErrorInfo() throws -> ICreateErrorInfo { | ||
var createErrorInfo = ICreateErrorInfoProjection.abiDefaultValue | ||
defer { ICreateErrorInfoProjection.release(&createErrorInfo) } | ||
try COMError.fromABI(SWRT_CreateErrorInfo(&createErrorInfo)) | ||
return try NullResult.unwrap(ICreateErrorInfoProjection.toSwift(createErrorInfo)) | ||
} | ||
|
||
/// Creates an instance of `IErrorInfo` with prepopulated fields. | ||
public func createErrorInfo(guid: GUID? = nil, source: String? = nil, description: String?, | ||
helpFile: String? = nil, helpContext: UInt32? = nil) throws -> IErrorInfo { | ||
let errorInfo = try createErrorInfo() | ||
if let guid { try errorInfo.setGUID(guid) } | ||
if let source { try errorInfo.setSource(source) } | ||
if let description { try errorInfo.setDescription(description) } | ||
if let helpFile { try errorInfo.setHelpFile(helpFile) } | ||
if let helpContext { try errorInfo.setHelpContext(helpContext) } | ||
return try errorInfo.queryInterface(IErrorInfoProjection.self) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters