我在VB中努力创建一个dll,该dll将对Python可见。
当我将dll导入Python时,没有VB函数是可见的。
以下是我的做法:
- 最简单的VB类
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`
我将其保存为 dll (从 Visual Studio 2010 构建)。
我尝试将其导入到其他 VB 项目中以检查是否正常工作(结果良好):
我将其加载到Python中并尝试使用: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
我试过使用MyDll.MyFunctions()
、MyDll.MyFunctions.AddMyValues(1,2)
和MyDll.MyFunctions.AddMyValues
代替MyDll.MyFunctions
,但是出了什么问题我并不理解。
PS. 这里有一个类似的未解决问题:在Python中调用VB DLL