Python import dll

后端 未结 4 1727
灰色年华
灰色年华 2020-12-03 14:35

How would I import a winDLL into python and be able to use all of its functions? It only needs doubles and strings.

4条回答
  •  难免孤独
    2020-12-03 14:43

    You've tagged the question ctypes and so it sounds like you already know the answer.

    The ctypes tutorial is excellent. Once you've read and understood that you'll be able to do it easily.

    For example:

    >>> from ctypes import *
    >>> windll.kernel32.GetModuleHandleW(0)
    486539264
    

    And an example from my own code:

    lib = ctypes.WinDLL('mylibrary.dll')
    #lib = ctypes.WinDLL('full/path/to/mylibrary.dll')
    func = lib['myFunc']#my func is double myFunc(double);
    func.restype = ctypes.c_double
    value = func(ctypes.c_double(42.0))
    

提交回复
热议问题