正在尝试获取可打印的rect for OS X应用程序。似乎涉及创建会话、页面格式、验证格式等。代码编译,但从PMCreateSession获得-50状态。我声明printSession不正确吗通常不需要处理太多不可执行的指针。
谢谢!
let printSession: UnsafeMutablePointer<PMPrintSession> = nil
let pmPageFormat: UnsafeMutablePointer<PMPageFormat> = nil
var status = PMCreateSession(printSession)
status = PMCreatePageFormat(pmPageFormat)
status = PMSessionDefaultPageFormat(printSession.memory, pmPageFormat.memory)
let changed: UnsafeMutablePointer<DarwinBoolean> = nil
status = PMSessionValidatePageFormat(printSession.memory, pmPageFormat.memory, changed)
changed.destroy()
var pRect = PMRect()
status = PMGetAdjustedPageRect(pmPageFormat.memory, &pRect)
Swift.print("pRect \(pRect)")
status = PMRelease(pmPageFormat)
status = PMRelease(printSession)
最佳答案
我声明printSession不正确吗?
可获得如下aPMPrintSession
:
// create a C Null pointer of type PMPrintSession
let printSession = unsafeBitCast(0, to: PMPrintSession.self)
// pass by & converts PMPrintSession to UnsafeMutablePointer<PMPrintSession>
PMCreateSession(&printSession)
…
// recast printSession to release memory
PMRelease( PMObject(printSession) )
或者,可以从Cocoa访问a
PMPrintSession
:let printInfo = NSPrintInfo.shared()
let printSession = PMPrintSession(printInfo.pmPrintSession())
通常不需要处理太多不可执行的指针
有关使用
NSPrintInfo
的更多信息,请参阅StackOverflow"How to use UnsafeMutablePointer in Swift?"有关将核心打印与Swift一起使用的完整示例,请参见GitHub上的004.42Apple_CorePrintingExample。
关于swift - PMCreateSession不创建打印 session ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36461514/