在python中调用vb dll [英] calling vb dll in python

查看:1227
本文介绍了在python中调用vb dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在vb中有一个函数转换成我想要在python中使用的dll。但是尝试使用它,我收到一个错误消息
这是VB功能

 功能DISPLAYNAME(名称)
MsgBox(Hello& Name&!)
结束函数

这是我如何在python中调用它$ c

 从ctypes import * 
test = windll.TestDLL
print test
print test.DISPLAYNAME(one)

但是我收到错误那么调用dll的正确方法是什么?

 追溯(最近的最后一次通话):
文件C: \Test\testdll.py,第4行在< module>
print test.DISPLAYNAME(one)
文件C:\Python26\lib\ctypes\__init __。py,第366行,__getattr__
func = self。 __getitem __(name)
文件C:\Python26\lib\ctypes\__init __。py,第371行,__getitem__
func = self._FuncPtr((name_or_ordinal,self))
AttributeError:未找到函数'DISPLAYNAME'

我一直在网路上看,但没有解决方案远。不能使用cdll,因为这是用于c progs。



我已经看了一些python和dll相关的问题,但是目前还没有解决方案适用于我的问题。 / p>

解决方案

这可能是一个范围问题,出于公共访问修饰符,外部调用者可能看不到该功能。尝试

 公共功能DISPLAYNAME(名称)
MsgBox(Hello& Name&! b $ b结束功能

在您的dll


So I have a function in vb that is converted to a dll that I want to use in python. However trying to use it, I get an error message this is the VB function

Function DISPLAYNAME(Name)
MsgBox ("Hello " & Name & "!")
End Function

and this is how I call it in python

from ctypes import *
test = windll.TestDLL
print test
print test.DISPLAYNAME("one")

But I get errors so what is the right way of calling the dll

Traceback (most recent call last):
  File "C:\Test\testdll.py", line 4, in <module>
    print test.DISPLAYNAME("one")
  File "C:\Python26\lib\ctypes\__init__.py", line 366, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python26\lib\ctypes\__init__.py", line 371, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'DISPLAYNAME' not found

I have been looking around online but no solution so far. Can't use cdll since this is for c progs.

I have looked at some of the python and dll related questions but no solution so far works for my issue.

解决方案

It might be a scoping issue, with out the Public access modifier, the function may not be visible to external callers. Try

Public Function DISPLAYNAME(Name)
MsgBox ("Hello " & Name & "!")
End Function

in your dll

这篇关于在python中调用vb dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆