smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
619 stars 156 forks source link

EnumWindows in GetWindows() crashes when encountering weird process name. #60

Closed NipunRamani99 closed 5 years ago

NipunRamani99 commented 5 years ago

On Visual Studio 2017, When I tried the GetWindowFrame example, at the point where the EnumWindows() enumerates through processes it encounters a weird title name which crashes the program. devenv_2018-09-21_12-30-29

Here is the weird name string: devenv_2018-09-21_12-36-11 I tested this part of the code seperately in CodeBlocks and it worked but it crashed in VS2017 but works on changing the type of name in Window struct from char[] to std::string.

What should I do if I don't want to simply change the type? Another possible fix I can think of is check if the int value of char is < 0 and then change the string.

smasherprog commented 5 years ago

maybe you could test changing the type to a wide string and see if that fixes it?

smasherprog commented 5 years ago

wait... I think it see a possible bug

Try adding \n to the end of the window name title after the copy is finished. It might be that it is not null terminated.

NipunRamani99 commented 5 years ago

Yep, added a null terminator and that fixed the problem. This problem is caused by buffer parameter in GetWindowTextA() that is pointing to invalid window name string which is not null terminated.

smasherprog commented 5 years ago

awesome. did you want to do a pull request? Otherwise, ill fix this later today.

smasherprog commented 5 years ago

Just pushed a fix for this try it out https://github.com/smasherprog/screen_capture_lite/commit/5100aefcda98c17dfd02d3d73526bd81dd7d9a86