我真的是个新手。我正在加载一个windows文件,并试图读取数组GetDfuFileInfo返回。实际上,我在ctype中加载了文件,因为我不知道如何将dfu_file*指针传递给GetDfuFileInfo函数。这有可能吗?
C++函数示例用法:
dfu_file* TheFile = ReadDfuFile(const char*);
dfu_file_info* Info = GetDfuFileInfo(dfu_file*);Python代码:
lib = ctypes.WinDLL('dfulib.dll')
func = lib.ReadDfuFile
func.restype = ctypes.c_void_p
func.argtypes = [ctypes.c_char_p]
func("file.dvu")编辑
也尝试过这样做:
lib = ctypes.WinDLL('dfulib.dll')
func = lib.ReadDfuFile
func.restype = ctypes.c_void_p
func.argtypes = [ctypes.c_char_p]
FileInfo = lib.GetDfuFileInfo
FileInfo.argtypes = [ctypes.c_void_p]
FileInfo.restype = None
s = func(r'file.dvu')
s = ctypes.cast(s, ctypes.c_char_p)
print FileInfo(s.value)产生异常:
WindowsError: exception: access violation reading 0x00000016
任何帮助都将不胜感激。
发布于 2014-06-19 12:58:35
示例代码看起来,此代码从kernel32.dll调用GetFileAttributesA函数
>>> from ctypes import *
>>> windll.LoadLibrary("kernel32.dll")
<WinDLL 'kernel32.dll', handle 77260000 at 2241ad0>
>>> windll.kernel32
<WinDLL 'kernel32', handle 77260000 at 225c2f0>
>>> windll.kernel32.GetFileAttributesA("c:/test/1.txt")
32有关详细信息,可以参考https://docs.python.org/2/library/ctypes.html。
https://stackoverflow.com/questions/24305920
复制相似问题