schmich / win32-window

Ruby interface to the Win32 window management APIs.
https://rubygems.org/gems/win32-window
MIT License
4 stars 0 forks source link

Segmentation fault when tried to access window modal dialog #7

Open pgundlupetvenkatesh opened 6 years ago

pgundlupetvenkatesh commented 6 years ago

I am trying to interact with a window dialog. When I use w = Window.find(:title => "Open") I get a segmentation fault at C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/win32-window-0.2.0.pre/lib/win32/window/window.rb:84 line. I have attached the console log here. I am running it on Ruby 64bit, IE browser - 11.0, Watir - 6.11.0, Watir-webdriver - 0.9.9 and win32-window - 0.2.0.pre

seg_fault.txt

schmich commented 6 years ago

It's not documented well, and it might not be the issue here, but the title parameter expects a regex, not a string. Can you try this instead? w = Window.find(title: /Open/)

Also, what version of Windows are you running?

pgundlupetvenkatesh commented 6 years ago

Okay, my bad. I have tried regex as well and I get the same error. Running on Windows 8.1 pro.

schmich commented 6 years ago

It works for me on Windows 10. I don't have access to 8.1 to test.

I'm trying to narrow down the issue. What's the simplest reproduction of the crash? If you open Notepad and then run the script below by itself outside of Watir/Cucumber/any testing framework, does it still crash?

require 'win32/window'
p Win32::Window.find(title: /Notepad/)
schmich commented 6 years ago

Also, another thing to check: do other methods work, e.g. Win32::Window.desktop or Win32::Window.foreground?

pgundlupetvenkatesh commented 6 years ago

Tried the notepad thing you suggested. So I have the Notepad window opened and I execute those two script in the Ruby Shell. I get the same segmentation fault error again. Attached the console error. seg_fault_new.txt

schmich commented 6 years ago

Strange. The call stack of the crash is definitely right in the middle of this library's code. This library is pretty much just a friendly wrapper around the win32-api library.

When finding a window, we just call Windows' native EnumWindows function via win32-api with our Ruby callback. win32-api handles all the marshalling and interface issues between Ruby and C.

My current guesses about the issue: 1) 32-/64-bit mismatch somewhere, 2) Ruby GC issue, 3) Win32 API incompatibility, 4) win32-api bug that was fixed (but not present in the 0.2.0-pre release of this library), 5) my misuse of win32-api somehow.

Let's take this library out of the picture entirely. Could you try running the script below? It just enumerates all open windows on your system and prints out their handles. If this works, it will narrow down the issue significantly.

gem install win32-api

require 'win32/api'

EnumWindows = Win32::API.new('EnumWindows', 'KP', 'L', 'user32')
callback = Win32::API::Callback.new('LP', 'I') { |handle, param|
  puts handle
  true
}

EnumWindows.call(callback, '')