Problem closing handle from OpenDesktop

Started by
1 comment, last by daerid 19 years, 3 months ago
Hi, I'm having problems closing the handle from OpenDesktop. I have a app which interacts with the desktop. Every 5 sec, it searchs the desktop. I call the OpenDesktop func in Visual C++, do my thing, then I call CloseDesktop when I'm finished. Hence while( running == true) { if(time > 5.0) { hdesk = OpenDesktop(..); .... ..do something CloseDesktop(hdesk); } } I get an error 170 (ERROR_BUSY) when I try to close the handle. The app itself still works, but as you can imagine I run out of handles eventually because the the hdesk handle is not closed and each call to open gives me a new handle. I could just call OpenDesktop once and save the handle in a variable, but I would like to know why I can't close the handle in the 1st place. Thanks.
Advertisement
DId you make a call to CreateDesktop to create the desktop first? Then you would call OpenDesktop to obtain the object - but no memory is created with the open, only with the create. You would only call CloseDesktop after the program is done because "The CloseDesktop function will fail if any thread in the calling process is using the specified desktop handle or if the handle refers to the initial desktop of the calling process.".

Disclaimer - I have never heard of these functions before - all of what I have posted are form just looking over the MSDN and not actually trying this myself [smile]. I hope it can be of some use!

- Drew
Don't worry about closing the handle to the desktop of the calling process.

Just call OpenDesktop once at the start of the program, and store that value.
daerid@gmail.com

This topic is closed to new replies.

Advertisement