1

I have Dll function int WriteData (const char* buffer); and I want to pass HEX file or bin file to this function.

My unsuccessfull attempts was smth like that:

f=open("FENCEE_Monitor.HEX") # open file
array=bytearray(f)           # convert it 
writeFile=ctypes.c_char_p(array)

dll.WriteData(writeFile)

Thank you for help.

WITC
  • 127
  • 9

1 Answers1

1

Listing [Python.Docs]: ctypes - A foreign function library for Python.

A couple mentions:

Here's an example for the printf function, although it's not recommended to manually load msvcrt.dll:

[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q063411355]> sopr.bat
*** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***

[prompt]> echo "Dummy text">file.txt

[prompt]> "e:\Work\Dev\VEnvs\py_pc064_03.07.06_test0\Scripts\python.exe"
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes as ct
>>>
>>>
>>> f = open("file.txt", "rb")
>>> t = f.read()
>>> f.close()
>>> t
b'"Dummy text"\r\n'
>>>
>>> printf = ct.WinDLL("msvcrt").printf  # @TODO: DON'T use msvcrt this way! This is for demo purposes only!!!
>>>
>>> printf.argtypes = [ct.c_char_p]
>>> printf.restype = ct.c_int
>>>
>>> printf(t)
"Dummy text"
14
CristiFati
  • 38,250
  • 9
  • 50
  • 87