How to run DLL file in Python


What is a DLL file?

DLL is a dynamic link library

It is a way to realize the concept of shared function library in Microsoft Windows operating system

First of all, let’s explain the concept of DLL (dynamic linkable Library). You can simply regard DLL as a kind of warehouse, which provides you with some variables, functions or classes that can be used directly. In the history of warehouse development, it has experienced the era of “no database static link library dynamic link library”. Both static link library and dynamic link library share code. If static link library is used, the instructions in lib will be directly included in the final generated EXE file whether you want to or not. However, if a DLL is used, the DLL does not need to be included in the final EXE file. When the EXE file is executed, it can dynamically reference and unload the DLL file independent of exe. Another difference between the static link library and the dynamic link library is that the static link library can no longer contain other dynamic link libraries or static libraries, and can also contain other dynamic or static link libraries in the dynamic link library.

To execute DLL files in Python:

from ctypes import cdll
def run_dll(dll_path, execute_function):
  Execute the functions specified inside the DLL file
  :param dll_ Path: the path of the DLL file
  :param execute_ Function: the name of the function to be executed inside the DLL file
  dll_ object =  cdll.LoadLibrary (dll_ Path) ා instantiate DLL object
  eval('dll_ object.{}()'.format(execute_ Call the specified program in the DLL file
if __name__ == '__main__':
  path = r'C:\Users\evaliu\Desktop\example.dll'
  run_dll(dll_path=path, execute_function='communication_test')


The above is the method of Python running DLL file introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and the editor will reply to you in time. Thank you very much for your support to the developeppaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!