I'm trying to access the C-funtions with the following prototypes through ctypes library in python
HandleT OpenFile (const char *FName, ResultT *ReturnCode);
ResultT GetItem (HandleT handle, void **data, int *len);
ResultT is an enum.
Let's say the python code i'm using is:
FILE = "E:/LogData/!d1fx/D1F1"
clib = ctypes.CDLL('c_libs\RAWRD64.dll')
data = ctypes.c_void_p(0)
datalen = ctypes.c_int()
result = ctypes.c_int()
handle = ctypes.c_void_p()
handle = clib.OpenFile(FILE, ctypes.byref(result))
#debug output
print ("handle: %d, ret: %d" %(handle, result.value))
clib.GetItem(handle, ctypes.byref(data), ctypes.byref(datalen))
#debug output
print ("result: %d" % (result.value))
print ("data: %s, len: %d" %(data.value, datalen.value))
With python 2.7 on a Windows 7 machine this code works. I've been migrating to a Windows 10 machine now and in the same step trying to port this code to python 3.8.
The first issue I encounterd was, that openFile() returned, that it cannot open the file. This could be fixed by adding an encoding to the file name.
handle = clib.OpenFile(FILE.encoding("ANSI"), ctypes.byref(result))
However, GetItem() now raises the following exception:
handle: 389636160, ret: 0
Traceback (most recent call last):
File ".\test_clib.py", line 19, in <module>
clib.GetItem(handle, ctypes.byref(data), ctypes.byref(datalen))
OSError: exception: access violation reading 0x0000000017396040
Why does this code raise an exception with pyhton 3.8 and work with 2.7? Is there any difference in how DLLs are treated with ctypes?