I am making an attempt to entry the C-funtions with the next prototypes by ctypes library in python
HandleT OpenFile (const char *FName, ResultT *ReturnCode); ResultT GetItem (HandleT deal with, void **information, int *len);
ResultT is an enum.
As an example the python code i am utilizing is:
FILE = "E:/LogData/!d1fx/D1F1" clib = ctypes.CDLL('c_libsRAWRD64.dll') information = ctypes.c_void_p(0) datalen = ctypes.c_int() consequence = ctypes.c_int() deal with = ctypes.c_void_p() deal with = clib.OpenFile(FILE, ctypes.byref(consequence)) #debug output print ("deal with: %d, ret: %d" %(deal with, consequence.worth)) clib.GetItem(deal with, ctypes.byref(information), ctypes.byref(datalen)) #debug output print ("consequence: %d" % (consequence.worth)) print ("information: %s, len: %d" %(information.worth, datalen.worth))
With python 2.7 on a Home windows 7 machine this code works. I have been migrating to a Home windows 10 machine now and in the identical step making an attempt to port this code to python 3.8.
The primary concern I encounterd was, that openFile() returned, that it can’t open the file. This may very well be fastened by including an encoding to the file identify.
deal with = clib.OpenFile(FILE.encoding("ANSI"), ctypes.byref(consequence))
Nonetheless, GetItem() now raises the next exception:
deal with: 389636160, ret: 0 Traceback (most up-to-date name final): File ".test_clib.py", line 19, in <module> clib.GetItem(deal with, ctypes.byref(information), ctypes.byref(datalen)) OSError: exception: entry violation studying 0x0000000017396040
Why does this code elevate an exception with pyhton 3.Eight and work with 2.7? Is there any distinction in how DLLs are handled with ctypes?