Python import dll

后端 未结 4 1732
灰色年华
灰色年华 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:53

    c-types NOTE!

    Using WinDLL (and wintypes, msvcrt) is windows specific imports and does not always work, even on windows! The reason is that it depends on your python installation. Is it native Windows (or using Cygwin or WSL)?

    For ctypes, the more portable and correct way is to use cdll like this:

    import sys
    import ctypes
    from ctypes import cdll, c_ulong
    
    kFile = 'C:\\Windows\\System32\\kernel32.dll'
    mFile = 'C:\\Windows\\System32\\msvcrt.dll'
    
    try: 
        k32    = cdll.LoadLibrary(kFile)
        msvcrt = cdll.LoadLibrary(mFile)
    except OSError as e:
        print("ERROR: %s" % e)
        sys.exit(1)
    
    # do something...
    

提交回复
热议问题