[python-win32] handle is invalid?

Tim Roberts timr at probo.com
Wed Jul 22 20:02:30 CEST 2009


sudheer sivathasan wrote:
> Hey guys,
>  
> Another quick question. I'm still trying to do the thing in the email
> below. But this time im trying to use the win32api.GetModuleFileName
> function. It requires a PyHandle as an input which I think I've
> managed to get by using the function handle =
> w.FindWindow(0,str(w.GetWindowText(w.GetForegroundWindow()))) where
> handle would serve as the input to the win32api.GetModuleFileName
> function and w = win32gui. However I'm getting a 'the handle is
> invalid' error.

Yes, because FindWindow returns a window handle, and GetModuleFileName
expects a module handle.  Handles are not all alike.  Roger Upole gave
you exactly the recipe you need.  Was there something about his reply
that you didn't like?

By the way, your code there is somewhat silly: the FindWindow call will
return exactly the same handle that GetForegroundWindow already gave you.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list