wpb wrote: ↑30 Aug 2023, 13:58
I have a simple version of GetActiveExplorerPath() that looks like this:
Code: Select all
GetExplorerCOMObject(hwndExplorerWindow := "")
{
if !hwndExplorerWindow
MouseGetPos(, , &hwndExplorerWindow)
for Window in ComObject("Shell.Application").Windows
{
if (Window.hwnd = hwndExplorerWindow)
return Window
}
}
When I use it to get a COM handle on an Explorer window, that handle appears to persist even if I later do
This means that if the window was one from an external drive, I can no longer "eject" it using the "Safely Remove Hardware" icon in the taskbar.
How do I release the COM object or the Window object properly, to stop this happening?
Not sure if this fits here.
You might have to open a new thread and request Lexicos's (or who ever else can speak to that) insight about the inner workings of AHK.
Unless the variable is global or otherwise passed up to a larger scope, one would assume that some garbage collection would pick that up
I don't know anything about COM objects, but it might be worth checking if there are explicit "close". "free" or "destroy" methods for this one?
I feel like there's a more pertinent keyword on the tip of my mental tongue, but I can't quite get there...
Hey, have you looked at
this?
Possibly, you could call
Release on it. Manage copies of references by using
AddRef (But you probably won't have to create separate references. "Copying" the reference within AHK shouldn't change anything, I think, unless you do something fancy with dereferenced pointers/addresses. Otherwise, it all just points to the same thing. I think.)
I clearly don't know what I'm talking about, but I thought I'd throw my two cents in the ring, for better or for worse
EDIT:
yes, "release" is one of the keywords I was looking for, and you were already using it; you probably already know about the things discussed in the article. If so: Sorry to pollute the thread :/