我正在运行 Python 3.9,64 位,并已使用 VS 2022 将 libharu 和一些扩展编译到 DLL 中,包括 libpng。在添加最少的代码调整以查找 VS 运行时 DLL(libhpdf)后,DLL 可以加载到 Python 中。 dll 依赖,并且似乎可以工作(绑定中只有 5 个 .py 文件) 我已经构建了启用 PTRACE 的 DLL,以跟踪进度。还使用该 DLL 动态构建了 C 演示,它们都可以工作,生成 PDF。
我正在尝试运行绑定中包含的 python 演示示例,arc_demo.py 希望生成相同的 PDF 文件
我可以说一切正常,直到添加文档的行:
pdf = HPDF_New (error_handler, NULL)
与使用示例的编译 C 版本获得的跟踪类似的输出。
但是... var“pdf”不是 HP_AddPage() 所期望的,因为在发出下一个调用时,要添加页面
page = HPDF_AddPage (pdf)
我遇到了这个:
**ctypes.ArgumentError:参数 1:<class>:int 太长,无法转换**</class>
我认为这可能与原始绑定仅使用 32 位构建和测试有关。另一个嫌疑点是移植的 ctypes。
所以现在我正在修改绑定,主要是hpdf.py。
目前,正在与 Python 到 DLL 的相互通信进行斗争,检查 ctypes 是否按预期处理事情。使用 byref
,将 *pdf * 转换为 c_void_p
,...没有运气。如果调用是通过 ref(c_void_p(pdf)) 完成的,我会消除错误,但无法正确访问 HPDF_Doc 结构的内容
有什么建议吗?你可能会提供帮助吗?使用基于 C 的 DLL 调试 Python 的对比方法?
谢谢, 伊格纳西奥
PS:最终将为 Haru PDF 内部结构编写类。但这会在我能够无错误地运行 python 示例之后发生。
正确答案
if/python/hpdf.py
中的ctypes
接口没有为所有函数定义.argtypes
。对于 64 位句柄和指针来说,为每个函数定义正确的参数类型尤其重要。最初的开发人员可能不明白这一点,如从 windll
转换为 cdll
接口所示。 windll
使用 __stdcall
调用约定并需要知道参数大小。
例如,hpdf_doc
被定义为 hpdf_handle
,它被定义为 ctypes.c_void_p
。这是 64 位操作系统上的 64 位指针。 hpdf_new
和 hpdf_addpage
定义为:
#hpdf_doc hpdf_new (hpdf_error_handler user_error_fn, void *user_data) hpdf_new=haru.hpdf_new hpdf_new.restype=hpdf_doc #hpdf_page hpdf_addpage (hpdf_doc pdf) hpdf_addpage=haru.hpdf_addpage hpdf_addpage.restype=hpdf_page
ctypes
假设传递给 hpdf_addpage
的参数是 c_int
因为 to 没有 argtypes。句柄值是 >32 位,因此出现错误。理想情况下,所有函数都应显式声明其参数类型,以便 ctypes
可以进行类型检查并正确地将参数从 python 对象编组(转换)为 c 类型,例如:
HPDF_AddPage.argtypes = HPDF_Doc, # must be a list or tuple...comma makes this a 1-tuple. HPDF_New.argtypes = HPDF_Error_Handler, c_void_p
请注意,参数类型必须基于 ctypes
类型。您必须仔细跟踪参数并为每个函数声明 .argtypes
。
以上是有人尝试将 LibHaru 的 Python 绑定更新为 Python 3.9(64 位)吗?的详细内容。更多信息请关注PHP中文网其他相关文章!

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomeSdata,performance-Caliticalcode,orinterFacingWithCcccode.1)同质性data:arrayssavememorywithtypedelements.2)绩效code-performance-clitionalcode-clitadialcode-critical-clitical-clitical-clitical-clitaine code:araysofferferbetterperperperformenterperformanceformanceformancefornalumericalicalialical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactssperformance.2)listssdonotguaranteeconeeconeconstanttanttanttanttanttanttanttanttimecomplecomecomecomplecomecomecomecomecomecomplecomectaccesslikearrikearraysodo。

toAccesselementsInapythonlist,useIndIndexing,负索引,切片,口头化。1)indexingStartSat0.2)否定indexingAccessesessessessesfomtheend.3)slicingextractsportions.4)iterationerationUsistorationUsisturessoreTionsforloopsoreNumeratorseforeporloopsorenumerate.alwaysCheckListListListListlentePtotoVoidToavoIndexIndexIndexIndexIndexIndExerror。

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通过使用pyenv、venv和Anaconda来管理不同的Python版本。1)使用pyenv管理多个Python版本:安装pyenv,设置全局和本地版本。2)使用venv创建虚拟环境以隔离项目依赖。3)使用Anaconda管理数据科学项目中的Python版本。4)保留系统Python用于系统级任务。通过这些工具和策略,你可以有效地管理不同版本的Python,确保项目顺利运行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基于基于duetoc的iMplation,2)2)他们的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函数函数函数函数构成和稳定性构成和稳定性的操作,制造


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3汉化版
中文版,非常好用

记事本++7.3.1
好用且免费的代码编辑器

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。