我正在尝试使用ctypes将DLL导入Python 2.7.12 64位。为了缩小错误范围,我使用了Microsoft的MathLibrary DLL示例,并根据这些指令(https://msdn.microsoft.com/en-GB/library/ms235636.aspx)构建了自己的示例。我将其构建为x64版本并将生成的dll复制到C:\ root中以消除路径长度或拼写错误问题。我的机器运行Windows 7 Pro 64 Bit。
我的python代码是:
type instance Index (Bar n) = Int
type instance IxValue (Bar n) = Foo
instance Ixed (Bar n) where
ix i f (Bar v) = fmap Bar (ix i f v)
运行时会报告以下内容:
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 37 counts of IllegalAnnotationExceptions
Two classes have the same XML type name
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:277) [jaxb-api-2.2.12.jar:2.2.12]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:249) [jaxb-api-2.2.12.jar:2.2.12]
at javax.xml.bind.ContextFinder.find(ContextFinder.java:456) [jaxb-api-2.2.12.jar:2.2.12]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:656) [jaxb-api-2.2.12.jar:2.2.12]
at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:347) [cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:345) [cxf-core-3.1.4.jar:3.1.4]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0_131]
at org.apache.cxf.common.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:345) [cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:246) [cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:472) [cxf-rt-databinding-jaxb-3.1.4.jar:3.1.4]
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:327) [cxf-rt-databinding-jaxb-3.1.4.jar:3.1.4]
... 41 more
Two classes have the same XML type name
at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:106) [jaxb-impl-2.2.5.redhat-9.jar:2.2.5.jboss-2]
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:466) [jaxb-impl-2.2.5.redhat-9.jar:2.2.5.jboss-2]
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:298) [jaxb-impl-2.2.5.redhat-9.jar:2.2.5.jboss-2]
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:141) [jaxb-impl-2.2.5.redhat-9.jar:2.2.5.jboss-2]
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1163) [jaxb-impl-2.2.5.redhat-9.jar:2.2.5.jboss-2]
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:145) [jaxb-impl-2.2.5.redhat-9.jar:2.2.5.jboss-2]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_131]
at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_131]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:262) [jaxb-api-2.2.12.jar:2.2.12]
... 51 more
任何人都可以建议可能出现的问题吗?
由于
安迪
更新
@eryksun评论 - 这删除了LibraryLoader错误。但是我现在正在努力访问add函数并得到这个错误:
from ctypes import cdll, windll, c_long, c_int, create_string_buffer
test_dll = windll("C:\\MathLibrary.dll")
add = test_dll.add
答案 0 :(得分:1)
windll是ctypes模块中的一个对象。它不能像函数一样被调用(&#39;对象不可调用&#39;)。您可能想要引用其中一个方法并调用它。
test_dll = windll.<func_name>("C:\\MathLibrary.dll")
您可以使用__dir__()
查看对象属性和方法,或者更好的是,查看documentation。
答案 1 :(得分:0)
使用 'cdll' 会产生类似的错误消息“TypeError: 'LibraryLoader' object is not callable”。使用 'CDLL' 效果很好,所以问题出在 'cdl' 的大小写敏感,也可能是 'windll'。