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.
来源:https://stackoverflow.com/questions/29538031/call-dll-function-works-in-ironpython-doesnt-work-in-cpython3-4-gives-no-meth