我想为我的python项目使用DLL(ImageSearch.dll)。它最初是为autoit开发的。 这是au3文件:
Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
$result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
; If error exit
if $result[0]="0" then return 0
; Otherwise get the x,y location of the match and the size of the image to
; compute the centre of search
$array = StringSplit($result[0],"|")
$x=Int(Number($array[2]))
$y=Int(Number($array[3]))
if $resultPosition=1 then
$x=$x + Int(Number($array[4])/2)
$y=$y + Int(Number($array[5])/2)
endif
return 1
EndFunc
所以我尝试使用ctypes但是我有问题要获得变量“result”。实际上,在下面的脚本中,searchReturn的值是c_char_p(b'0'),而使用自动脚本,我有一个带有'|'的字符串在里面。
from ctypes import *
ImageSearchDLL = windll.LoadLibrary("ImageSearchDLL")
ImageSearch = ImageSearchDLL.ImageSearch
searchReturn = c_char_p(ImageSearch(0,0,1919,1079,'myPic.bmp'))
print(searchReturn)
我也尝试用c_int等传递参数,这会导致同样的问题。如果我不使用c_char_p(),我有一个int。我不明白为什么我得到一个int,标题显示它应该返回一个str。