windows – ruby win32apistructs(VerQueryValue)
发布时间:2020-09-18 15:41:43 所属栏目:Windows 来源:互联网
导读:我试图使用 win32-api library调用标准的Win32 API函数来获取文件版本信息. 3 version.dll函数是GetFileVersionInfoSize,GetFileVersionInfo和VerQueryValue.然后我调用kernel32.dll中的RtlMoveMemory来获取VS_FIXEDFILEINFO结构的副本(请参阅Microsoft文档:
|
我试图使用 win32-api library调用标准的Win32 API函数来获取文件版本信息. 3 version.dll函数是GetFileVersionInfoSize,GetFileVersionInfo和VerQueryValue.然后我调用kernel32.dll中的RtlMoveMemory来获取VS_FIXEDFILEINFO结构的副本(请参阅Microsoft文档:http://msdn.microsoft.com/en-us/library/ms646997(VS.85).aspx). 我从使用VB看到的一个例子中得出:http://support.microsoft.com/kb/139491. 我的问题是最终返回的数据似乎与预期的结构不匹配,实际上它甚至没有返回一致的值.我怀疑数据在某些时候会被破坏,可能是在VerQueryValue或RtlMoveMemory中. 这是代码: GetFileVersionInfoSize = Win32::API.new('GetFileVersionInfoSize','PP','I','version.dll')
GetFileVersionInfo = Win32::API.new('GetFileVersionInfo','PIIP','version.dll')
VerQueryValue = Win32::API.new('VerQueryValue','PPPP','version.dll')
RtlMoveMemory = Win32::API.new('RtlMoveMemory','PPI','V','kernel32.dll')
buf = [0].pack('L')
version_size = GetFileVersionInfoSize.call(myfile + " ",buf)
raise Exception.new if version_size == 0 #TODO
version_info = 0.chr * version_size
version_ok = GetFileVersionInfo.call(file,version_size,version_info)
raise Exception.new if version_ok == 0 #TODO
addr = [0].pack('L')
size = [0].pack('L')
query_ok = VerQueryValue.call(version_info," ",addr,size)
raise Exception.new if query_ok == 0 #TODO
# note that at this point,size == 4 -- is that right?
fixed_info = Array.new(13,0).pack('L*')
RtlMoveMemory.call(fixed_info,fixed_info.length)
# fixed_info.unpack('L*') #=> seemingly random data,usually only the first two dwords' worth and the rest 0.
这是我工作的完整代码,以防其他人正在寻找这样的功能.
返回一个包含四个产品/文件版本号部分的数组(即,在dll文件属性窗口中称为“文件版本”): def file_version ref,options = {}
options = {:path => LIBDIR,:extension => 'dll'}.merge(options)
begin
file = File.join(ROOT,options[:path],"#{ref}.#{options[:extension]}").gsub(///,"")
buf = [0].pack('L')
version_size = GetFileVersionInfoSize.call(file + " ",buf)
raise Exception.new if version_size == 0 #TODO
version_info = 0.chr * version_size
version_ok = GetFileVersionInfo.call(file,version_info)
raise Exception.new if version_ok == 0 #TODO
addr = [0].pack('L')
size = [0].pack('L')
query_ok = VerQueryValue.call(version_info,size)
raise Exception.new if query_ok == 0 #TODO
fixed_info = Array.new(18,0).pack('LSSSSSSSSSSLLLLLLL')
RtlMoveMemory.call(fixed_info,addr.unpack('L')[0],fixed_info.length)
fixed_info.unpack('LSSSSSSSSSSLLLLLLL')[5..8].reverse
rescue
[]
end
end (编辑:日照站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- macos – 如何使用AFP将Windows客户端连接到OSX服务器
- Windows Phone 7 – 如何在WIndows Phone应用程序中访问Nav
- 在非Qt应用程序中使用基于Qt的DLL
- 如何在Windows上正确使用node.js child_process.spawn()重定
- win10远程桌面连接win2012 错误
- Atitit webdav 的问题 -------------大文件传输问题 在某些
- Windows环境 安装dlib(python) 总结
- 如何在Windows上制作相同高度的SWT按钮,文本和标签?
- winapi – 避免UAC,但使用Windows服务启动升级过程
- windows-8 – 屏幕关闭时,WinRT应用程序可以继续运行吗?
