# GetComputerName using Win32API
require 'Win32API'
def get_computer_name()
params = [ 'P', # lpBuffer
'P' # lpnSize
]
rVal = 'L'
myname = "\0" * 255
mysize = [255].pack('L')
getComputerNameA = Win32API.new("kernel32","GetComputerNameA",params,rVal)
results = getComputerNameA.call(myname,mysize)
return myname.gsub(/\000/,''), mysize.unpack('L')[0]
end
p get_computer_name
···
----- Original Message -----
From: LeRoy, Brian D.
To: 'Shashank Date'
Sent: Thursday, March 20, 2003 3:16 PM
Subject: RE: win32api createprocess trouble
Thanks for the help! There's something I'm not understanding here. I had the snapshot working in a previous app, but now I'm having trouble. If you have time, my simple sample test app is resulting in a seg fault:
params = [
'P', #lpBuffer
'L' #lpnSize
]
rVal = 'L'
myname = '' * 16
mysize = 16
GCM = Win32API.new("kernel32","GetComputerNameA",params,rVal)
results = GCM.call(myname,0)
What am I missing? Is it something obvious?