Use DLL with python and ctypes -
i use dll (imagesearch.dll) python project. developped autoit. here au3 file:
func _imagesearcharea($findimage,$resultposition,$x1,$y1,$right,$bottom,byref $x, byref $y, $tolerance) ;msgbox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) if $tolerance>0 $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" return 0 ; otherwise x,y location of match , size of image ; compute centre of search $array = stringsplit($result[0],"|") $x=int(number($array[2])) $y=int(number($array[3])) if $resultposition=1 $x=$x + int(number($array[4])/2) $y=$y + int(number($array[5])/2) endif return 1 endfunc
so try use ctypes have problems variable "result". indeed, in following script, value of searchreturn c_char_p(b'0') whereas autoit script, have string '|' inside it.
from ctypes import * imagesearchdll = windll.loadlibrary("imagesearchdll") imagesearch = imagesearchdll.imagesearch searchreturn = c_char_p(imagesearch(0,0,1919,1079,'mypic.bmp')) print(searchreturn)
i try pass arguments c_int, etc. , leads same problem. if don't use c_char_p(), have int. don't understand why got int, header shows should return str.
ok thought should use cdll after many attempts , defining arguments way, solve problem. thank cdarke :)
here final script :
import ctypes dllfunc = ctypes.windll.loadlibrary('imagesearchdll.dll') dllfunc.imagesearch.argtypes = (ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_char_p,) dllfunc.imagesearch.restype = ctypes.c_char_p _result = dllfunc.imagesearch(0, 0, 1920, 1080, b"mypic.bmp") print(_result.decode('utf-8'))
Comments
Post a Comment