I am getting the following error from my code:
Traceback (most recent call last):
File "<pyshell#309>", line 1, in <module>
get_handles('Python26')
File "C:\Python26\e__handle.py", line 19, in get_handles
ctypes.windll.user32.EnumWindows(ctypes.c_long(fun ction),ctypes.byref(ctypes.c_char_p(arg)))
WindowsError: exception: access violation writing 0x0064BCF6
From some searching online I think it's because I'm not able to properly pass the function's address pointer.
-
from e__handle import EnumWindowsProc, EnumChildWindowsProc
-
import ctypes
-
global listed
-
global parents
-
listed=[]
-
-
arg=str(parent_search_text)+'|'+str(parent_case_sensitive)+'|'+str(document)+'|'+str(child_search_text)+'|'+str(child_case_sensitive)+'|'+str(get_children)+'|'+str(id(EnumChildWindowsProc))
-
function=id(EnumWindowsProc)
-
-
ctypes.windll.user32.EnumWindows(ctypes.c_long(function),ctypes.byref(ctypes.c_char_p(arg)))
-
if document==True:
-
return listed
-
else:
-
listed=[]
So the jist of the code is that I have defined EnumWindowsProc further down. I import the function so now it should be associated with an memory location. I use id(EnumWindowsProc) to get the address, but when I try to make it a pointer the pointer ends up referencing the location of the integer and not the function. Please let me know if this isn't clear.
I changed the one line to
ctypes.windll.user32.EnumWindows(ctypes.POINTER(fu nction),ctypes.byref(ctypes.c_char_p(arg)))
and got a different error of:
Traceback (most recent call last):
File "<pyshell#311>", line 1, in <module>
get_handles('Python26')
File "C:\Python26\e__handle.py", line 17, in get_handles
ctypes.windll.user32.EnumWindows(ctypes.POINTER(fu nction),ctypes.byref(ctypes.c_char_p(arg)))
TypeError: must be a ctypes type
Any ideas?