Skip to content Skip to sidebar Skip to footer

Using Python Ctypes And Libc To Write Void Pointer To Binary File

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 acquisition appears to

Solution 1:

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)

Post a Comment for "Using Python Ctypes And Libc To Write Void Pointer To Binary File"