B
Berger, Daniel
Hi all,
Windows XP
Ruby 1.8.1
How do I pass a straight-up string to a function in the Win32API? I
understand how to pad a buffer store a value in a buffer, but not how to
convert a Ruby string to an LPCTSTR, for example. I'm guessing that I
pack'd it wrong.
require "Win32API"
module Win32
CloseEventLog = Win32API.new("advapi32","CloseEventLog","p","i")
OpenEventLog = Win32API.new("advapi32","OpenEventLog","pp","p")
class EventLog
def initialize(source,machine=0)
lpSource = [source].pack("p")
unless 0 == machine
lpMachine = [machine].pack("p")
end
@h = OpenEventLog.call(source,machine)
return @h
end
def close
CloseEventLog.call(@h)
end
end
end
if $0 == __FILE__
e = EventLog.new("Application") # results in "NULL pointer given"
e.close
end
This is part of an effort to provide pure-ruby versions of the
win32utils code. Please help.
Regards,
Dan
Windows XP
Ruby 1.8.1
How do I pass a straight-up string to a function in the Win32API? I
understand how to pad a buffer store a value in a buffer, but not how to
convert a Ruby string to an LPCTSTR, for example. I'm guessing that I
pack'd it wrong.
require "Win32API"
module Win32
CloseEventLog = Win32API.new("advapi32","CloseEventLog","p","i")
OpenEventLog = Win32API.new("advapi32","OpenEventLog","pp","p")
class EventLog
def initialize(source,machine=0)
lpSource = [source].pack("p")
unless 0 == machine
lpMachine = [machine].pack("p")
end
@h = OpenEventLog.call(source,machine)
return @h
end
def close
CloseEventLog.call(@h)
end
end
end
if $0 == __FILE__
e = EventLog.new("Application") # results in "NULL pointer given"
e.close
end
This is part of an effort to provide pure-ruby versions of the
win32utils code. Please help.
Regards,
Dan