【问题标题】:VB dll doesnt work in python with ctypes (function * not found)VB dll 在带有 ctypes 的 python 中不起作用(函数 * 未找到)
【发布时间】:2013-03-11 18:44:41
【问题描述】:

我很难在 VB 中创建对 python 可见的 dll,

当我将 dll 导入 python 时,没有一个 VB 函数可见

这是我的工作:

  1. 有史以来最简单的 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`
  1. 我将其保存为 dll(从 Visual Studio 2010 构建)

  2. 我尝试通过将它导入到其他 VB 项目中是否可以正常工作(它工作正常):

    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. 我将它加载到python中并尝试使用它:
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() , MyDll.MyFunctions.AddMyValues(1,2) , MyDll.MyFunctions.AddMyValues

这里有什么问题?没看懂。

PS。有类似的未解决问题:calling vb dll in python

【问题讨论】:

标签: python vb.net dll ctypes


【解决方案1】:

你不能这样做。您生成的 DLL 是一个 .NET 程序集,或者,如果您公开一个 COM 接口,它就是一个 COM 组件。

Python 的ctypes 模块只支持C ABI DLLs

【讨论】:

  • aaaah :/ 那么有什么方法可以在 python 中使用 vb dll 吗?来自 COM 的 Aprat,它似乎不是那么健壮(注册名称、每个名称一个 dll、硬更新等)
  • @Intelligent-Infrastructure 可能有一个用于 Python 的 .NET 绑定,但我实际上对此表示怀疑——COM 似乎是唯一的方法。
【解决方案2】:

在您的 dll 上使用 dumpbin.exe,使用 /exports/linkermember 选项来查看 DLL 中实际导出的名称是什么。

【讨论】:

    猜你喜欢
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    相关资源
    最近更新 更多