Click here to Skip to main content
15,896,557 members

Comments by KulaGGin (Top 6 by date)

KulaGGin 27-Nov-23 9:41am View    
"Reading a file that is being edited at the same time sounds like a really bad idea."

It's not a bad idea. A perfectly valid use case: encrypting file in-place with AES using streams, so that you can encrypt big files and it's all good and well.

"I'm afraid you could get unexpected results and impossible-to-find bugs..."

No. That's wrong. You just write your code against the Stream, StreamReader and StreamWriter classes and you do TDD, so everything is tested, and then you also apply good software engineering practices, such as Clean Code, Clean Architecture, DDD, SOLID principles, GRASP principles, etc. Then you don't get unexpected results and bugs: everything is well-engineered and tested, and everything just works.
KulaGGin 24-Jul-23 11:42am View    
Ok, but the answer is still wrong: GetWindowThreadProcessId still doesn't get window handle from a process ID. GetWindowThreadProcessId gets a process ID using the window handle you provide to it. And what you provide to it is hCurWnd = 0. So it doesn't do anything, it'll just put 0 in your curProcessID. This function is still completely broken. See the docs for the function yourself: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid
Why did you do this? You asked the question, then wrote a completely broken answer without testing it or even making sense whatsoever: the docs clearly tell us what the function does, then accepted it as the solution. Karma farming?
KulaGGin 23-Jul-23 4:54am View    
Deleted
Your answer doesn't have a solution. The function is absolutely broken and doesn't even attempt at doing what the question asks. This answer should be deleted.
KulaGGin 23-Jul-23 4:42am View    
"which will cause it to enumerate all the windows from all the processes"
It won't do that. GetWindowThreadProcessId doesn't locate handle of a window by process id, the function takes in a valid window handle and the identifier of the process that created the window.
Also, he tries to get a window using FindWindowEx and passes a null hCurWnd, which will return him null.
Then the do-while will run once and exit. The GetWindowThreadProcessId won't return anything meaningful, will probably leave dwProcessID at 0, then it will push null hCurWnd to the vector, print, exit the loop and then the function.
There's like everything wrong with that function, feels like it was a troll answer or something.
KulaGGin 23-Jul-23 4:38am View    
This is absolutely a wrong answer. First of all, you're redefining your dwProcessID argument with the local variable dwProcessID that you define later and overwrite it with 0, so your local variable hides the argument and the argument isn't even used anywhere. So it's already broken. But even if you remove your local variable and use the argument, the function GetWindowThreadProcessId doesn't locate handle of a window by process id, the function takes in a valid window handle and the identifier of the process that created the window.
This function is completely broken and doesn't answer the question.