The original code incorrectly tests the result of pisw->Item(v, &pidisp)
. Weird, because it does use the correct check later on.
The problem is that there are many success return values besides S_OK
. Your fix is correct, you should use SUCCEEDED(hr)
, but you incorrectly moved the loop INSIDE the SUCCEEDED(hr)
test. You should check SUCCEEDED(hr)
for every value of V_I4(&v)
.
Your S_FALSE
result is because you now call hr = pisw->Item(v, &pidisp);
before the loop, which means v
is uninitialized (garbage). Assume for a moment that its garbage value is 728365. S_FALSE
means: the call succeeded, but there are less than 728365 windows.