JRuby and JNA

Discussion in 'Ruby' started by Curator1, Apr 1, 2010.

  1. Curator1

    Curator1 Guest

    Ok folks, help out a noob. What am I doing wrong on the
    SystemParameterInfoA call for switching the desktop - Windows7, JRuby
    1.4. I'm pretty sure I got the signature right, no blowup, no error,
    just no action as well. My kernel32 call works fine, so JNA is
    properly there. Code followed by output. Any help greatly
    appreciated!

    import com.sun.jna.ptr.LongByReference
    import com.sun.jna.ptr.IntByReference
    Kernel32 = com.sun.jna.NativeLibrary.getInstance('kernel32')
    GetDiskFreeSpace = Kernel32.getFunction('GetDiskFreeSpaceExA')
    avail = LongByReference.new
    total = LongByReference.new
    total_free = LongByReference.new
    num = GetDiskFreeSpace.invokeInt(["S:\\", avail, total,
    total_free].to_java)
    puts "available: #{avail.value}"
    puts "total: #{total.value}"
    puts "total_free #{total_free.value}"
    puts "Everything fine upto here"
    begin
    User32=com.sun.jna.NativeLibrary.getInstance('user32')
    SysP=User32.getFunction('SystemParametersInfoA')
    thirdarg=true
    changedesktop=LongByReference.new(20)
    puts changedesktop
    zero=IntByReference.new(0)
    puts zero
    changenow=LongByReference.new(2)
    puts changenow
    s2=java.lang.String[1].new()
    s2[0]=java.lang.String.new("c:\\22_bikini.bmp")
    s=com.sun.jna.StringArray.new(s2)
    puts SysP.invokeInt([changedesktop,zero,s,changenow].to_java)
    rescue => err
    puts err
    end

    ****OUTPUT BEGINS***
    available: 255961772032
    total: 1000202240000
    total_free 255961772032
    Everything fine upto here
    com.sun.jna.ptr.LongByReference@7d9f68
    com.sun.jna.ptr.IntByReference@7d9f78
    com.sun.jna.ptr.LongByReference@7d9f88
    -1073741822 <---- is returned by SystemParametersInfoA
    Curator1, Apr 1, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Slim Baltagi
    Replies:
    0
    Views:
    398
    Slim Baltagi
    Dec 15, 2007
  2. Knute Johnson

    Re: JNA performance

    Knute Johnson, May 8, 2011, in forum: Java
    Replies:
    6
    Views:
    305
    Tom Anderson
    May 9, 2011
  3. Lew

    Re: JNA performance

    Lew, May 8, 2011, in forum: Java
    Replies:
    3
    Views:
    735
    Roedy Green
    May 9, 2011
  4. Lew
    Replies:
    7
    Views:
    281
  5. Replies:
    0
    Views:
    142
Loading...

Share This Page