[Q] ruby 1.8.6 p287 and p383 crashing in WIN32OLE_EVENT.message_loop

Sorry for the long subject. I wanted to make sure folks interested in WIN32OLE stuff saw it.

Anyway, I am doing some application automation on Windows using the WIN32OLE classes. In this particular case, I have registered event handlers for a bunch of possible events that may be generated by another Windows application. I have tested about a dozen of these handlers and all is well. However, I added one more and now when I trigger the event that calls it, ruby crashes.

If I am using ruby 1.8.6 patch level 287, it generates a segfault and writes the usual message:

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.

It also gives me a line number in my code. This line corresponds to this code:

WIN32OLE_EVENT.message_loop

I took the error message at face value and decided this was a ruby bug so I upgraded to patch level 383. (For this installation I used the one-click installer available from rubyinstaller.org, preview 2).

It still crashes but now it doesn't give me any code line or write any message at all.

I'm not well versed in Windows programming so I don't really know how to debug this. Here is what I have tried:

1. I've narrowed the "cause" down to the line of code that generates the event that the handler will get on the next call to WIN32OLE_EVENT.message_loop. If I comment it out, the program continues to run. With it in, the program crashes.

The line in question is calling a method on a WIN32OLE COM object that was previously retrieved via WIN32OLE.new. The method called generates a callback event after it finishes processing. This same COM object is also used for making other method calls that are all succeeding just fine.

2. I thought that perhaps I had a bug in my event handler code. I commented it out. The crash still occurs.

This leads me to believe that the event being received is causing the crash. I have *no idea* how to get deeper on this without getting the ruby C source and mucking about inside the #message_loop code.

Anyone have any ideas on how I can solve this? If you need more information, let me know. At this point this crash is a showstopper for me because I *need* to be able to process the event that is causing the crash.

cr

I know we discussed this a bit offline, but I'm curious if you see the
same behavior with pr-win32ole. You can checkout the code at:

svn checkout http://pure.rubyforge.org/svn/pr-win32ole

I'm curious if it exhibits the same behavior. If it does, we can
probably figure out what's wrong with the C code, too. With pr-
win32ole, you can at least use the debugger. :slight_smile:

Regards,

Dan

PS - No folks, pr-win32ole has not been officially released yet.

···

On Sep 2, 11:48 am, Chuck Remes <cremes.devl...@mac.com> wrote:

Sorry for the long subject. I wanted to make sure folks interested in
WIN32OLE stuff saw it.

Anyway, I am doing some application automation on Windows using the
WIN32OLE classes. In this particular case, I have registered event
handlers for a bunch of possible events that may be generated by
another Windows application. I have tested about a dozen of these
handlers and all is well. However, I added one more and now when I
trigger the event that calls it, ruby crashes.

If I am using ruby 1.8.6 patch level 287, it generates a segfault and
writes the usual message:

>> This application has requested the Runtime to terminate it in an
>> unusual
>> way.
>> Please contact the application's support team for more information.

It also gives me a line number in my code. This line corresponds to
this code:

WIN32OLE_EVENT.message_loop

I took the error message at face value and decided this was a ruby bug
so I upgraded to patch level 383. (For this installation I used the
one-click installer available from rubyinstaller.org, preview 2).

It still crashes but now it doesn't give me any code line or write any
message at all.

I'm not well versed in Windows programming so I don't really know how
to debug this. Here is what I have tried:

1. I've narrowed the "cause" down to the line of code that generates
the event that the handler will get on the next call to
WIN32OLE_EVENT.message_loop. If I comment it out, the program
continues to run. With it in, the program crashes.

The line in question is calling a method on a WIN32OLE COM object that
was previously retrieved via WIN32OLE.new. The method called generates
a callback event after it finishes processing. This same COM object is
also used for making other method calls that are all succeeding just
fine.

2. I thought that perhaps I had a bug in my event handler code. I
commented it out. The crash still occurs.

This leads me to believe that the event being received is causing the
crash. I have *no idea* how to get deeper on this without getting the
ruby C source and mucking about inside the #message_loop code.

Anyone have any ideas on how I can solve this? If you need more
information, let me know. At this point this crash is a showstopper
for me because I *need* to be able to process the event that is
causing the crash.

It can't seem to load a few of its dependencies like "windows/com".

1. The gem doesn't have a dependency on the windows-api gem.

2. The windows-api gem, after installation, doesn't have a lot of the files that pr-win32ole wants to load.

#2 leads me to believe that you have a super-secret version of the windows-api gem containing all this cool new stuff but it hasn't been released yet.

Where can I find this super-secret code? Alternately, email me the gem at the above address. :slight_smile:

cr

···

On Sep 2, 2009, at 1:51 PM, Daniel Berger wrote:

On Sep 2, 11:48 am, Chuck Remes <cremes.devl...@mac.com> wrote:

Sorry for the long subject. I wanted to make sure folks interested in
WIN32OLE stuff saw it.

Anyway, I am doing some application automation on Windows using the
WIN32OLE classes. In this particular case, I have registered event
handlers for a bunch of possible events that may be generated by
another Windows application. I have tested about a dozen of these
handlers and all is well. However, I added one more and now when I
trigger the event that calls it, ruby crashes.

If I am using ruby 1.8.6 patch level 287, it generates a segfault and
writes the usual message:

This application has requested the Runtime to terminate it in an
unusual
way.
Please contact the application's support team for more information.

It also gives me a line number in my code. This line corresponds to
this code:

WIN32OLE_EVENT.message_loop

I took the error message at face value and decided this was a ruby bug
so I upgraded to patch level 383. (For this installation I used the
one-click installer available from rubyinstaller.org, preview 2).

It still crashes but now it doesn't give me any code line or write any
message at all.

I'm not well versed in Windows programming so I don't really know how
to debug this. Here is what I have tried:

1. I've narrowed the "cause" down to the line of code that generates
the event that the handler will get on the next call to
WIN32OLE_EVENT.message_loop. If I comment it out, the program
continues to run. With it in, the program crashes.

The line in question is calling a method on a WIN32OLE COM object that
was previously retrieved via WIN32OLE.new. The method called generates
a callback event after it finishes processing. This same COM object is
also used for making other method calls that are all succeeding just
fine.

2. I thought that perhaps I had a bug in my event handler code. I
commented it out. The crash still occurs.

This leads me to believe that the event being received is causing the
crash. I have *no idea* how to get deeper on this without getting the
ruby C source and mucking about inside the #message_loop code.

Anyone have any ideas on how I can solve this? If you need more
information, let me know. At this point this crash is a showstopper
for me because I *need* to be able to process the event that is
causing the crash.

I know we discussed this a bit offline, but I'm curious if you see the
same behavior with pr-win32ole. You can checkout the code at:

svn checkout http://pure.rubyforge.org/svn/pr-win32ole

I'm curious if it exhibits the same behavior. If it does, we can
probably figure out what's wrong with the C code, too. With pr-
win32ole, you can at least use the debugger. :slight_smile:

<snip>

It can't seem to load a few of its dependencies like "windows/com".

1. The gem doesn't have a dependency on the windows-api gem.

2. The windows-api gem, after installation, doesn't have a lot of the
files that pr-win32ole wants to load.

There is no gem for pr-win32ole. All you should need to do is:

gem install windows-pr

That should install win32-api and windows-api automatically. It should
then "just work" as long as RUBYOPT is set. If it doesn't, please give
me a specific error you're getting.

Regards,

Dan

Well, I ran 'gem build pr-winole32.gemspec' so it was easy to install.

I now have everything up and going. When I run my program, it crashes on a call to WIN32OLE_EVENT.message_loop.

starting...
C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:701:in `=': index 8 out of string (IndexError)
         from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:701:in `ole_val2variant'
         from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:4481
         from (eval):3:in `call'
         from (eval):3:in `DispatchMessage'
         from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:5034:in `ole_msg_loop'
         from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:5039:in `message_loop'
         from //.host/Shared Folders/My Documents/NetBeansProjects/ChuckKit/lib/main.rb:165

If that trace looks crappy, view it here: http://pastie.org/603650

I need to point out that it is crashing way earlier than the stock WIN32OLE stuff. This test program works just fine using MRI's WIN32 classes. I figured once I had everything up and going I could trigger that event which was causing my other code to bomb out.

cr

···

On Sep 2, 2009, at 4:43 PM, Daniel Berger wrote:

<snip>

It can't seem to load a few of its dependencies like "windows/com".

1. The gem doesn't have a dependency on the windows-api gem.

2. The windows-api gem, after installation, doesn't have a lot of the
files that pr-win32ole wants to load.

There is no gem for pr-win32ole. All you should need to do is:

gem install windows-pr

That should install win32-api and windows-api automatically. It should
then "just work" as long as RUBYOPT is set. If it doesn't, please give
me a specific error you're getting.

Okay, dug into the pr-win32ole code and this is what I found.

Line 701 was trying to access index 8 of a string with only 4 characters. Backing up the stack I looked at where it was passed in from and see that the +pvarResult+ variable passed into the lambda had the value "\n\000". The lambda in question is on line 4400.

I don't know this code well enough to say where that came from originally, but that explains the IndexError anyway. It looks like the code that operates on those strings assumes they are 16 characters long. That assumption blew it up.

cr

···

On Sep 2, 2009, at 4:58 PM, Chuck Remes wrote:

On Sep 2, 2009, at 4:43 PM, Daniel Berger wrote:

<snip>

It can't seem to load a few of its dependencies like "windows/com".

1. The gem doesn't have a dependency on the windows-api gem.

2. The windows-api gem, after installation, doesn't have a lot of the
files that pr-win32ole wants to load.

There is no gem for pr-win32ole. All you should need to do is:

gem install windows-pr

That should install win32-api and windows-api automatically. It should
then "just work" as long as RUBYOPT is set. If it doesn't, please give
me a specific error you're getting.

Well, I ran 'gem build pr-winole32.gemspec' so it was easy to install.

I now have everything up and going. When I run my program, it crashes on a call to WIN32OLE_EVENT.message_loop.

starting...
C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:701:in `=': index 8 out of string (IndexError)
       from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:701:in `ole_val2variant'
       from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:4481
       from (eval):3:in `call'
       from (eval):3:in `DispatchMessage'
       from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:5034:in `ole_msg_loop'
       from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:5039:in `message_loop'
       from //.host/Shared Folders/My Documents/NetBeansProjects/ChuckKit/lib/main.rb:165

If that trace looks crappy, view it here: http://pastie.org/603650

Hello,

C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:4481
       from (eval):3:in `call'
       from (eval):3:in `DispatchMessage'
       from

Okay, dug into the pr-win32ole code and this is what I found.

Line 701 was trying to access index 8 of a string with only 4 characters. Backing up the stack I looked at where it was passed in from and see that the +pvarResult+ variable passed into the lambda had the value "\n\000". The lambda in question is on line 4400.

I don't know this code well enough to say where that came from originally, but that explains the IndexError anyway. It looks like the code that operates on those strings assumes they are 16 characters long. That assumption blew it up.

How about commenting the 3 lines from line 4480 to line 4482?
Does it work?

          ary2ptr_dispparams(outargv, pdispparams)
       end

       # if pvarResult
       # WIN32OLE.ole_val2variant(result,pvarResult)
       # end
       S_OK
    })

  Regards,
  Masaki Suketa

···

At 09/03/2009 07:23 AM, Chuck Remes wrote:

It's been fixed in SVN. I'm curious if your code works with the
updated version.

Regards,

Dan

···

On Sep 2, 4:23 pm, Chuck Remes <cremes.devl...@mac.com> wrote:

On Sep 2, 2009, at 4:58 PM, Chuck Remes wrote:

> On Sep 2, 2009, at 4:43 PM, Daniel Berger wrote:

>> <snip>

>>> It can't seem to load a few of its dependencies like "windows/com".

>>> 1. The gem doesn't have a dependency on the windows-api gem.

>>> 2. The windows-api gem, after installation, doesn't have a lot of
>>> the
>>> files that pr-win32ole wants to load.

>> There is no gem for pr-win32ole. All you should need to do is:

>> gem install windows-pr

>> That should install win32-api and windows-api automatically. It
>> should
>> then "just work" as long as RUBYOPT is set. If it doesn't, please
>> give
>> me a specific error you're getting.

> Well, I ran 'gem build pr-winole32.gemspec' so it was easy to install.

> I now have everything up and going. When I run my program, it
> crashes on a call toWIN32OLE_EVENT.message_loop.

> starting...
> C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:
> 701:in `=': index 8 out of string (IndexError)
> from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
> win32ole.rb:701:in `ole_val2variant'
> from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
> win32ole.rb:4481
> from (eval):3:in `call'
> from (eval):3:in `DispatchMessage'
> from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
> win32ole.rb:5034:in `ole_msg_loop'
> from C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/
> win32ole.rb:5039:in `message_loop'
> from //.host/Shared Folders/My Documents/NetBeansProjects/
> ChuckKit/lib/main.rb:165

> If that trace looks crappy, view it here: http://pastie.org/603650

Okay, dug into the pr-win32ole code and this is what I found.

Line 701 was trying to access index 8 of a string with only 4
characters. Backing up the stack I looked at where it was passed in
from and see that the +pvarResult+ variable passed into the lambda had
the value "\n\000". The lambda in question is on line 4400.

I don't know this code well enough to say where that came from
originally, but that explains the IndexError anyway. It looks like the
code that operates on those strings assumes they are 16 characters
long. That assumption blew it up.

Commenting out those lines fixes (hides?) the problem described above. It now runs the program successfully.

However, this pure ruby version of the library still crashes when I run the code described in my original post. It crashes without writing any error message to the Output window in NetBeans. I *assume* it is crashing somewhere in #message_loop but I don't know that for sure.

Is there any easy way to instrument the win32ole code so I can pinpoint the crash location?

cr

···

On Sep 4, 2009, at 8:39 AM, Masaki Suketa wrote:

Hello,

At 09/03/2009 07:23 AM, Chuck Remes wrote:

C:/Ruby/lib/ruby/gems/1.8/gems/pr-win32ole-1.0.0/lib/pr/win32ole.rb:4481
      from (eval):3:in `call'
      from (eval):3:in `DispatchMessage'
      from

Okay, dug into the pr-win32ole code and this is what I found.
Line 701 was trying to access index 8 of a string with only 4 characters. Backing up the stack I looked at where it was passed in from and see that the +pvarResult+ variable passed into the lambda had the value "\n\000". The lambda in question is on line 4400.
I don't know this code well enough to say where that came from originally, but that explains the IndexError anyway. It looks like the code that operates on those strings assumes they are 16 characters long. That assumption blew it up.

How about commenting the 3 lines from line 4480 to line 4482?
Does it work?

        ary2ptr_dispparams(outargv, pdispparams)
     end

     # if pvarResult
     # WIN32OLE.ole_val2variant(result,pvarResult)
     # end
     S_OK
  })

Hello,

How about commenting the 3 lines from line 4480 to line 4482?
Does it work?

        ary2ptr_dispparams(outargv, pdispparams)
     end

     # if pvarResult
     # WIN32OLE.ole_val2variant(result,pvarResult)
     # end
     S_OK
  })

Commenting out those lines fixes (hides?) the problem described above. It now runs the program successfully.

However, this pure ruby version of the library still crashes when I run the code described in my original post. It crashes without writing any error message to the Output window in NetBeans. I *assume* it is crashing somewhere in #message_loop but I don't know that for sure.

Is there any easy way to instrument the win32ole code so I can pinpoint the crash location?

I would like to know more detail about the event when the code
crashes.

Anyway, I am doing some application automation on Windows using the
WIN32OLE classes. In this particular case, I have registered event
handlers for a bunch of possible events that may be generated by another
Windows application. I have tested about a dozen of these handlers and
all is well. However, I added one more and now when I trigger the event
that calls it, ruby crashes.

Does the event expect the return value from event handler?
If so, what kind of the return value the event expect?
For example, the NavigateComplete2 of InternetExplorer is as following,
and does not expect the return value(VOID).

   VOID NavigateComplete2(pDisp[in], URL[in])

Or could you show me the IDL of the event?

   Regards,
   Masaki Suketa

···

At 09/04/2009 11:29 PM, Chuck Remes wrote:
At 09/03/2009 02:48 AM, Chuck Remes wrote: