Python runtime DLL file

What is a DLL file?

DLL file is a dynamic link library (English: Dynamic-link library, DLL for short)
it is Microsoft's shared library concept of an implementation of the Microsoft Windows operating system

First to elaborate on the concept of DLL (Dynamic Linkable Library), you can simply put the DLL as a kind of warehouse, it gives you some of the variables can be directly used, the function or class. In the history of the warehouse has experienced the era of "no library - dynamic link library - Static Link Library". Static and dynamic link library Link library is sharing the code, if the static link library, regardless of whether you are willing, lib the instructions are generated directly included in the final EXE file in the. However, if the use of DLL, the DLL does not have to be included in the final EXE file, you can "dynamic" references and uninstall the standalone EXE and DLL files EXE file execution. Another difference between static and dynamic link library DLL statically linked libraries is that no longer contain other static libraries or dynamic link libraries, the dynamic link library and may further comprise other further static or dynamic link library.

Implementation of DLL files with Python:

from ctypes import cdll


def run_dll(dll_path, execute_function):
    """
    执行DLL文件内部指定的函数
    :param dll_path: DLL文件的所在路径
    :param execute_function: DLL文件内部要被执行的函数名
    :return:
    """
    dll_object = cdll.LoadLibrary(dll_path)  # 实例化DLL对象
    eval('dll_object.{}()'.format(execute_function))  # 调用DLL文件内的指定程序


if __name__ == '__main__':
    path = r'C:\Users\evaliu\Desktop\example.dll'
    run_dll(dll_path=path, execute_function='communication_test')
Published 27 original articles · won praise 10 · views 369

Guess you like

Origin blog.csdn.net/weixin_43750377/article/details/103992043