cosmo0920 / windows-pr

A collection of Windows functions, constants and macros predefined for you for win32-api
23 stars 9 forks source link

Example code not working #11

Open sschuberth opened 8 years ago

sschuberth commented 8 years ago

When trying to run the synopsis example from the README I get:

C:/Ruby/lib/ruby/gems/2.3.0/gems/windows-api-0.4.4/lib/windows/api.rb:333:in `initialize': uninitialized constant Windows::API::Win32 (NameError)
        from C:/Ruby/lib/ruby/gems/2.3.0/gems/windows-pr-1.2.4/lib/windows/path.rb:54:in `new'
        from C:/Ruby/lib/ruby/gems/2.3.0/gems/windows-pr-1.2.4/lib/windows/path.rb:54:in `<module:Path>'
        from C:/Ruby/lib/ruby/gems/2.3.0/gems/windows-pr-1.2.4/lib/windows/path.rb:4:in `<module:Windows>'
        from C:/Ruby/lib/ruby/gems/2.3.0/gems/windows-pr-1.2.4/lib/windows/path.rb:3:in `<top (required)>'
        from C:/Ruby/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
        from C:/Ruby/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
        from C:/Ruby/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
        from ./b.rb:3:in `<main>'

As you can see form the path names, this is with Ruby 2.3.0, windows-pr 1.2.4 and windows-api 0.4.4.

sschuberth commented 8 years ago

@djberg96 I just realized the same error occurs when using the example code from the windows-api project's synopsis, so the issue probably is in that gem instead.

djberg96 commented 8 years ago

@sschuberth I will take a look at this tonight, as I'm not sure right off.

I should also mention that win32-api and windows-api are in maintenance mode only, as I pretty much exclusively use ffi now instead.

sschuberth commented 8 years ago

@djberg96 Thanks! While I'm aware of the increased use of ffi, so far I've not found a higher-level wrapper around it that supports the handle APIs. In particular, I'm interested in the wrapper around NtQueryObject.

djberg96 commented 8 years ago

It's working for me. Did you install win32-api and windows-api?

Note that you will need the Devkit in order to install win32-api because I'm not putting out precompiled binaries any more.

sschuberth commented 8 years ago

Yes, I have the DevKit installed, and had installed the gems successfully:

$ gem install win32-api windows-api
Successfully installed win32-api-1.5.3-universal-mingw32
Parsing documentation for win32-api-1.5.3-universal-mingw32
Done installing documentation for win32-api after 0 seconds
Successfully installed windows-api-0.4.4
Parsing documentation for windows-api-0.4.4
Done installing documentation for windows-api after 0 seconds
2 gems installed

Still, I'm getting the error. Do I need to require anything else than exactly what is given in the example?

djberg96 commented 8 years ago

@sschuberth Please show me the actual script that you are trying to run.

sschuberth commented 8 years ago

Here it goes:

require 'windows/path'

class Foo
  include Windows::Path

  if PathIsRoot.call("C:\\") > 0
    #...
  end

  # or

  if PathIsRoot("C:\\")
    #...
  end
end

The only thing I changed compared to the example is to comment out the ... lines. I'm saving this as a.rb and running it as ruby a.rb.

djberg96 commented 7 years ago

@sschuberth Still hitting this? @cosmo0920 Are you able to confirm/deny?

sschuberth commented 7 years ago

I just did a fresh install with RubyInstaller-2.4.1-2, did gem install win32-api windows-api windows-pr, and now the example basically seems to work. The original error I saw is gone, but now I get

a.rb:6:in `<class:Foo>': undefined method `PathIsRoot' for Foo:Class (NoMethodError)

So it seems that doing if PathIsRoot("C:\\") > 0 works, while doing if PathIsRoot("C:\\") does not. Is that intended?

djberg96 commented 7 years ago

Glad it's mostly working. As for the behavior change, I'll have to defer to @cosmo0920.

cosmo0920 commented 7 years ago

Thanks for notifying it. I'll investigate this issue.

cosmo0920 commented 7 years ago

I think that this gem is only win32-api gem wrapper, so it should handle Windows API as <WindowsAPI>.call(argments).

I've saved the below as example.rb

require 'windows/path'

class Foo
  include Windows::Path

  if PathIsRoot.call("C:\\") > 0
    #...
  end

  # or
  if PathIsRoot("C:\\") > 0
    #...
  end
end

I got the following error:

./example.rb:11:in `<class:Foo>': undefined method `PathIsRoot' for Foo:Class (NoMethodError)
        from ./example.rb:3:in `<main>'

I didn't get success to work if PathIsRoot("C:\\") > 0. :<

sschuberth commented 7 years ago

Yeah, that's exactly what I wrote above already. The question is: Should the if PathIsRoot("C:\\") syntax work?

cosmo0920 commented 7 years ago

AFAIK, if PathIsRoot("C:\\") syntax should work within method or top-level like as irb environment, but does not work outside method.