ironpython调用c dll,调用dll函数在IronPython中起作用,在CPython3.4中不起作用,给出“没有方法匹配给定参数”。错误...

For a project I need to include a DLL in Python. I'm using CPython3.4 and for including the dll I use pythonnet clr module (pythonnet-2.0.0.dev1-cp34-none-win_amd64.whl). In the dll I need a function that gives me a continuous update of a measurement. The dll is written in VB.net, the function that I need is shown below:

Public Sub AdviseStart(ByVal item As Integer, ByVal a As Action(Of Object)) Implements IConversation.AdviseStart

_parameterPoller.RegisterCallback(item, a)

End Sub

This is the code that I have written in python to call this function:

import clr

clr.AddReference('dll name')

from dll import SetupMonitor

monitor = SetupMonitor(None, None, None)

# call to the dll function

# Everytime the measurement is changed the "test" function should be executed

monitor.AdviseStart(8, test)

def test(data):

print("Value: " + str(data))

For the sake of my further project I want to use Python3.4 and not Ironpython.

I tested this code in python3.4 and 2.7 and I got this error:

No method matches given arguments

I am 100% sure that the error is from the AdviseStart function. Because when I use the same code with IronPython it works. In Ironpython this codes gives the output I expect:

Value: -74

The goal of this function is that everytime a new measurement is made the function "test" will be called. Everything for the measurement and calling is in the dll. Is there anyway I can make this function work in any CPython version?

解决方案

There were some problems with integer arguments in the 64 bit builds. As far as I know that particular problem has been solved, but it would have been after that build you are using was released.

Try getting the source from github (https://github.com/renshawbay/pythonnet) and build that instead. To build and install it you just run "python setup.py install" (or any of the usual setup.py commands).

If it still doesn't work you can build a debug version by setting CONFIG="Debug" in setup.py and rebuilding. You will then be able to attach the visual studio debugger to your python process and step through the python.net code to see what signatures it's finding and why it's not matching with the arguments you're calling it with.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值