跳到主要內容

在 Python 中使用 DLL 檔

參考網址:
簡單示例  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

留言

匿名表示…
PNXBET is a premier licensed gaming operator of broad variety|all kinds} of online on line casino games and sportsbook matches. We host greater than 50 on line casino providers with over 5,000 on line casino games, hundreds of live on line casino tables, and 35,000 month-to-month sports activities occasions to bet. We take nice SM카지노 satisfaction in providing a user-friendly with innovative technology platform and best in class user experience to our bettors.