參考網址:
簡單示例 https://stackoverflow.com/questions/252417/how-can-i-use-a-dll-file-from-python
完整說明 ctypes module
https://docs.python.org/3/library/ctypes.html#module-ctypes
標題:How can I use a DLL file from Python?
作者:paxdiablo https://stackoverflow.com/users/14860/paxdiablo
It's very easy to call a DLL function in Python. I have a self-made DLL file with two functions: add and sub which take two arguments.
add(a, b) returns addition of two numbers
sub(a, b) returns substraction of two numbers
The name of the DLL file will be "demo.dll"
Program:
from ctypes import*
# give location of dll
mydll = cdll.LoadLibrary("C:\\demo.dll")
result1= mydll.add(10,1)
result2= mydll.sub(10,1)
print "Addition value:"+result1
print "Substraction:"+result2
Output:
Addition value:11
Substraction:9
簡單示例 https://stackoverflow.com/questions/252417/how-can-i-use-a-dll-file-from-python
完整說明 ctypes module
https://docs.python.org/3/library/ctypes.html#module-ctypes
標題:How can I use a DLL file from Python?
作者:paxdiablo https://stackoverflow.com/users/14860/paxdiablo
It's very easy to call a DLL function in Python. I have a self-made DLL file with two functions: add and sub which take two arguments.
add(a, b) returns addition of two numbers
sub(a, b) returns substraction of two numbers
The name of the DLL file will be "demo.dll"
Program:
from ctypes import*
# give location of dll
mydll = cdll.LoadLibrary("C:\\demo.dll")
result1= mydll.add(10,1)
result2= mydll.sub(10,1)
print "Addition value:"+result1
print "Substraction:"+result2
Output:
Addition value:11
Substraction:9
留言