JRuby and JNA

C

Curator1

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top