VB dll doesnt work in python with ctypes (function * not found)

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

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:

  1. Simplest ever VB class
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` 
  1. I save it as a dll (Build from Visual Studio 2010)

  2. I try if it works by importing it into othoer VB project (it works fine):

    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 
  1. I load it into python and try to use it:
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

回答1:

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.



回答2:

Use dumpbin.exe on your dll, with the /exports or maybe the /linkermember option to see what the actual exported names in the DLL are.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!