Ptyon ctypes: WindowsError when using function pointer

I try to use Python types to work with DLLs, but sometimes I encounter a problem when I try to call a function passed as a pointer to another function.

A bit of background ... I'm trying to create a userpace file system using Dokan (version 0.6.0). In a way, Dokan is mostly FUSE for Windows. I wrapped the dokan header file with ctypes (similar to pydokan ). This header file contains a definition for a function pointer that looks like this:

typedef int (WINAPI *PFillFindData) (PWIN32_FIND_DATAW, PDOKAN_FILE_INFO);

It also contains a prototype of another function.

int (DOKAN_CALLBACK *FindFilesWithPattern) (
     LPCWSTR,
     LPCWSTR,
     PFillFindData,
     PDOKAN_FILE_INFO);

The relevant ctypes definitions are as follows

PFillFindData = ctypes.WINFUNCTYPE(ctypes.c_int,
                                   PWIN32_FIND_DATAW, 
                                   PDOKAN_FILE_INFO)

FindFilesWithPattern = ctypes.WINFUNCTYPE(ctypes.c_int,
                                          ctypes.c_wchar_p,
                                          ctypes.c_wchar_p,
                                          PFillFindData,
                                          PDOKAN_FILE_INFO)

(FindFilesWithPattern) FillFindData, . :

def FindFilesWithPattern(self,
                         FileName,
                         SearchPattern,
                         FillFindData,
                         DokanFileInfo):
    if FileName == '\\':
        File = WIN32_FIND_DATAW(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_READONLY, 
                                FILETIME(1, 1),
                                FILETIME(1, 1), 
                                FILETIME(1, 1), 
                                0, 
                                len(self.HelloWorldText), 
                                0, 
                                0, 
                                'Hello_World.txt',
                                'Hello_~1.txt')
        pFile = PWIN32_FIND_DATAW(File)
        FillFindData(pFile, DokanFileInfo)
        return 0
    else:
        return -ERROR_FILE_NOT_FOUND

:

Traceback (most recent call last):
    File "_ctypes/callbacks.c", line 313, in 'calling callback function'
    File "src/test.py", line 385, in FindFilesWithPattern
        FillFindData(pFile, DokanFileInfo)
WindowsError: exception: access violation reading 0x0000000000000008

. , , . . , , . ( , , , , . , .)

, , , . , if , " ". , , , . , Heapy Meliae, , , Python 2.7 Windows 64-bit.

, 64- . , , , . , - Googling, , ctypes Win64. Dokan 64- . Python?

. .

. .

. python , (, PDOKAN_FILE_INFO). , , .

+3
1

? , . . .


Edit

, , ...

, DOKAN_OPERATIONS, , FindFilesWithPattern, DokanMain . , , Python. - ():

#Create the callback pointer type
PFINDFILESWITHPATTERN = ctypes.WINFUNCTYPE(ctypes.c_int,
                                          ctypes.c_wchar_p,
                                          ctypes.c_wchar_p,
                                          PFillFindData,
                                          PDOKAN_FILE_INFO) 

# Implement in Python
def FindFilesWithPatternImpl(...):
    # implementation

# Create a callback pointer object
FindFilesWithPattern = PFINDFILESIWTHPATTERN(FindFilesWithPatternImpl)

# Create the required structure listing the callback
dokan_op = DOKAN_OPERATIONS(...,FindFilesWithPattern,...)

# Register the callbacks
DokanMain(byref(dokan_op))

dokan_op , . Dokan, :

def mount():
    # Create structure locally
    dokan_op = DOKAN_OPERATIONS(...)
    # Spin off thread to mount Dokan
    threading.Thread(DokanMain,args=(byref(dokan_op),))

mount()

mount() dokan_op, . , , , . , , , , , FindFilesWithPattern Python, , . , . , , - , .

, ...

+2

All Articles