我正在尝试使用Python和ctype来使用ss深处的fuzzy.dll。到目前为止,我尝试过的一切都失败了,出现了访问冲突错误。下面是我在切换到包含fuzzy.dll和fuzzy.def文件的适当目录后所做的工作:
>>> import os,sys
>>> from ctypes import *
>>> fn = create_string_buffer(os.path.abspath("fuzzy.def"))
>>> fuzz = windll.fuzzy
>>> chash = c_char_p(512)
>>> hstat = fuzz.fuzzy_hash_filename(fn,chash)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
WindowsError: exception: access violation writing 0x00000200
>>>据我所知,我已经通过了适当的c_types。来自fuzzy.h
extern int fuzzy_hash_filename(char * filename, char * result)我就是无法通过那次非法访问。
发布于 2009-02-04 15:09:27
您的代码有两个问题:
windll.fuzzy,而应该使用cdll.fuzzy --来自ctypes文档:
cdll加载使用标准cdecl调用约定导出函数的库,而windll库使用stdcall调用约定调用函数。chash),您应该声明一个缓冲区,而不是创建指向0x0000200的指针(=512) --这就是访问冲突的来源。使用create_string_buffer('\000' * 512)代替。因此,您的示例应该如下所示:
>>> import os, sys
>>> from ctypes import *
>>> fn = create_string_buffer(os.path.abspath("fuzzy.def"))
>>> fuzz = cdll.fuzzy
>>> chash = create_string_buffer('\000' * 512)
>>> hstat = fuzz.fuzzy_hash_filename(fn,chash)
>>> print hstat
0 # == successhttps://stackoverflow.com/questions/510443
复制相似问题