VB dll不工作在python与ctypes(功能*未找到) [英] VB dll doesnt work in python with ctypes (function * not found)
问题描述
当我将dll导入到python中时,VB函数都不可见。
这是我做的:
- 最简单的VB类
-
将其保存为dll(从Visual Studio 2010生成)
-
我尝试通过将其导入到othoer VB项目(它可以正常工作)工作:
- 我将其加载到python并尝试使用它:
- Simplest ever VB class
I save it as a dll (Build from Visual Studio 2010)
I try if it works by importing it into othoer VB project (it works fine):
- I load it into python and try to use it:
公共类MyFunctions
公共功能AddMyValues(ByVal Value1 As Double,ByVal Value2 As Double)
Dim Result As Double
Result = Value1 + Value2
返回结果
结束函数
结束类`
导入ClassLibrary1
模块Module1
Sub Main()
Dim Nowa As New ClassLibrary1.MyFunctions
Dim结果As String
Result = Nowa.AddMyValues(123,465.78).ToString
Console.WriteLine(Result)
Console.ReadLine()
End Sub
结束模块
从ctypes import *
MojaDLL = cdll.LoadLibrary(E:\\\ClassLibrary1.dll)
MojaDLL.MyFunctions
追溯(最近的最后一次调用):
文件< console>,第1行,< module>
文件C:\Python25\lib\ctypes\__init __。py,第361行,__getattr__
func = self .__ getitem __(name)
文件C:\\ $ P $ 25 $ {$}
AttributeError:函数'MyFunctions'未找到
$ b func = self._FuncPtr((name_or_ordinal,self))
属性错误: $ b
而不是MyDll.MyFunctions我也尝试过: MyDll.MyFunctions(),MyDll.MyFunctions.AddMyValues(1,2),MyDll.MyFunctions.AddMyValues
。
这里有什么问题?我不明白。
PS。有类似的未解决的问题:在python中调用vb dll
你不能这样做。您正在生产的DLL是一个.NET程序集,或者,如果您公开COM接口,它是一个COM组件。
Python的 ctypes
模块仅支持 C ABI DLL 。
I struggle to create dll in VB which will be visible for python,
none of VB functions are visible when I import dll into python
Here's what I do:
Public Class MyFunctions Public Function AddMyValues(ByVal Value1 As Double, ByVal Value2 As Double) Dim Result As Double Result = Value1 + Value2 Return Result End Function End Class`
Imports ClassLibrary1 Module Module1 Sub Main() Dim Nowa As New ClassLibrary1.MyFunctions Dim Result As String Result = Nowa.AddMyValues(123, 456.78).ToString Console.WriteLine(Result) Console.ReadLine() End Sub End Module
from ctypes import * MojaDLL = cdll.LoadLibrary("E:\\ClassLibrary1.dll") MojaDLL.MyFunctions Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Python25\lib\ctypes\__init__.py", line 361, in __getattr__ func = self.__getitem__(name) File "C:\Python25\lib\ctypes\__init__.py", line 366, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'MyFunctions' not found
instead of MyDll.MyFunctions i also tried: MyDll.MyFunctions() , MyDll.MyFunctions.AddMyValues(1,2) , MyDll.MyFunctions.AddMyValues
.
What's wrong here? I don't understand it.
PS. there's similar unsolved problem: calling vb dll in python
You cannot do this. The DLL you’re producing is a .NET assembly, or, if you expose a COM interface, it’s a COM component.
Python’s ctypes
module only supports C ABI DLLs.
这篇关于VB dll不工作在python与ctypes(功能*未找到)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!