From: Park Heesob Date: 2005-10-18T22:49:55+09:00 Subject: Re: Win32API and GetFileVersionInfo Hi, ----- Original Message ----- From: Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Tuesday, October 18, 2005 9:26 PM Subject: Win32API and GetFileVersionInfo > > Hi all, > > I searched the whole web in order to find answers to my questions > without much success. > > I'm writing a script that extract the version of executable files. I > use the Win32API and the following functions: > > GetFileVersionInfoSize > GetFileVersionInfo > VerQueryValue > > in this order. For GetFileVersionInfoSize and GettFileVersionInfo, > everything is working fine. But I'm totally lost at using > VerQueryValue. > > Here's what I'm doing: > > apiGetInfoFromVersion = Win32API.new("version", "VerQueryValue", > ['p','p','p','p'], 'v') > msgp = DL.malloc(DL.sizeof('P')) > infoBufferLength = DL.malloc(DL.sizeof('P')) > apiGetInfoFromVersion.call(infoVersion, "\\", msgp, infoBufferLength) > > > where infoVersion is the result of a previous call to > GetFileVersionInfo. > > How do I retrieve the information in msgp? I've tried many ways, > without any success. You can use memcpy. > Thank you in advance. > > Here is my version without dl require 'Win32API' VS_FIXEDFILEINFO = Struct.new("VS_FIXEDFILEINFO", :Signature, :StrucVersion, :FileVersionMS, :FileVersionLS, :ProductVersionMS, :ProductVersionLS, :FileFlagsMask, :FileFlags, :FileOS, :FileType, :FileSubtype, :FileDateMS, :FileDateLS) file = "c:\\work\\xxx.dll" apiGetFileVersionInfo = Win32API.new("version", "GetFileVersionInfo",['P','L','L','P'], 'L') apiGetFileVersionInfoSize = Win32API.new("version", "GetFileVersionInfoSize",['P','P'], 'L') apiGetInfoFromVersion = Win32API.new("version", "VerQueryValue",['P','P','P','P'], 'L') memcpy = Win32API.new('msvcrt','memcpy','PPL','P') size = apiGetFileVersionInfoSize.call(file,nil) infoVersion = "\0" * size apiGetFileVersionInfo.call(file,0,size,infoVersion) lplpBuffer = "\0" * 4 pLen = "\0" * 4 apiGetInfoFromVersion.call(infoVersion,"\\",lplpBuffer,pLen) lpBuffer = lplpBuffer.unpack("L")[0] bufSize = pLen.unpack("L*")[0] rbuf = "\0" * bufSize memcpy.call(rbuf,lpBuffer,bufSize) vs_fixedfileinfo = VS_FIXEDFILEINFO.new(*rbuf.unpack("L*")) HTH, Park Heesob