Using python ctypes and libc to write void pointer to binary file

前端 未结 1 1282
青春惊慌失措
青春惊慌失措 2021-01-06 05:52

I am using python ctypes and libc to interface with a vendor-provided DLL file. The purpose of the DLL file is to acquire an image from a camera.

The image acquisit

相关标签:
1条回答
  • 2021-01-06 06:18

    Specify argtypes, restype of the functions.

    import ctypes
    
    libc = ctypes.windll.msvcrt
    
    fopen = libc.fopen
    fopen.argtypes = ctypes.c_char_p, ctypes.c_char_p,
    fopen.restype = ctypes.c_void_p
    
    fwrite = libc.fwrite
    fwrite.argtypes = ctypes.c_void_p, ctypes.c_size_t, ctypes.c_size_t, ctypes.c_void_p
    fwrite.restype = ctypes.c_size_t
    
    fclose = libc.fclose
    fclose.argtypes = ctypes.c_void_p,
    fclose.restype = ctypes.c_int
    
    fp = fopen('output3.raw', 'wb')
    fwrite('Hello', 5, 1, fp)
    fclose(fp)
    
    0 讨论(0)
提交回复
热议问题