GetFileVersionInfo和VerQueryValue返回奇怪的值... [英] GetFileVersionInfo and VerQueryValue return strange values...

查看:81
本文介绍了GetFileVersionInfo和VerQueryValue返回奇怪的值...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试编写一个实用程序来解决"DLL Hell"问题.多个程序在2个或更多不同位置中安装同一DLL的2个不同版本的问题.现在,我可以只使用日期/时间戳和大小,但这可能导致我删除较新的 而不是较旧的版本...因此,我正在尝试查询dll文件中的版本资源. (如果它没有版本资源,我将其命名为旧版本,并将其定位为删除目标,因为最新版本具有版本资源.)

I am trying to write a utility to resolve a "DLL Hell" issue where multiple programs install 2 different versions of the same DLL in 2 or more different locations. Now, I could just use date/time stamp and size, but that could cause me to remove the newer as opposed to the older version... So, I'm trying to query the version resource in the dll files. (If it doesn't have a version resource, I'll just call it old and target it for removal since the newest versions have a version resource.)

无论如何,当我执行GetFileVersionInfoSize()调用时,该操作成功,并说版本信息为1452字节.因此,我分配了该字节数并调用GetFileVersionInfo并获得了该字节数.这是车轮脱落的地方.我叫VerQueryValue() 然后打印该结构的签名成员.根据http://msdn.microsoft.com/zh-cn/library/ms646997%28v=VS.85%29.aspx,它应为0xFEEF04BD.在随后的运行中,如果我击中相同的文件,将会获得多个结果.

Anyway, when I do the GetFileVersionInfoSize() call, that succeeds and says that the version info is 1452 bytes. So, I allocate that # of bytes and call GetFileVersionInfo and get that # of bytes. And here's where the wheels come off. I call VerQueryValue() and then print the signature member of the structure. According to http://msdn.microsoft.com/en-us/library/ms646997%28v=VS.85%29.aspx it should be 0xFEEF04BD. I get MULTIPLE results on subsequent runs hitting the same file.

如果有问题,我将其创建为CLR控制台应用程序,因此从理论上讲,我可以使用x64版本.如果我执行x64构建,则结构中什么也没有,尽管它说它成功读取了版本信息.对于32位版本,它会填充 结构,但看起来像垃圾.

If it matters, I created this as a CLR console application so I can -- in theory -- have an x64 version. If I do an x64 build, I get NOTHING in the structure, though it says it read the version information successfully. For a 32-bit build, it does populate the structure, but with what looks like garbage.

VS 2008如果重要的话......

VS 2008 if it matters....

//Helpme.cpp:主项目文件.

#include"stdafx.h"
#include"windows.h"
#include"winver.h"
#include"stdio.h"

使用名称空间System;

int checkver(LPCTSTR fname)
{
    DWORD尺寸;
    LPDWORD虚拟对象;
    DWORD dummy2;
   整数状态; <​​br/>     unsigned int dummy3;
    char * verinfo;
    VS_FIXEDFILEINFO fileinfo;

    versize = GetFileVersionInfoSize(fname,dummy);
   如果(versize!= 0)
    {
        verinfo =(char *)malloc(versize);
       如果(verinfo!= NULL)
        {
            memset(verinfo,0,versize);
           状态= GetFileVersionInfo(fname,dummy2,versize,verinfo);
           如果(状态!= 0)
            {
                __int64 foo = 0;
               控制台:: WriteLine(L"Got文件版本信息.");
               状态= VerQueryValue(verinfo,TEXT("\\""),(LPVOID *)& fileinfo,& dummy3);
                printf(返回的数据大小%d \ n结构%d \ n的大小",dummy3,sizeof(fileinfo));
                printf("Signature Value:%#X \ n",fileinfo.dwSignature);
            }
           其他
            {
               控制台:: WriteLine(L无法获取文件版本信息.");
                goto errexit;
            }
        }
       其他
        {
            Console :: WriteLine(L无法为版本信息缓冲区分配内存.");
            goto errexit;
        }
    }
   其他
    {
       控制台:: WriteLine(L无法读取文件的版本信息");
        goto errexit;
    }
   返回0;
errexit:返回-1;
}


int main(array< System :: String ^> ^ args)
{
    int foo;

   控制台:: WriteLine(L"Hello World");
    foo = checkver(L"C:\\ Windows \\ System32 \\ aepic.dll");
   返回0;
}

// Helpme.cpp : main project file.

#include "stdafx.h"
#include "windows.h"
#include "winver.h"
#include "stdio.h"

using namespace System;

int checkver(LPCTSTR fname)
{
    DWORD versize;
    LPDWORD dummy;
    DWORD dummy2;
    int status;
    unsigned int dummy3;
    char *verinfo;
    VS_FIXEDFILEINFO fileinfo;

    versize = GetFileVersionInfoSize(fname,dummy);
    if (versize != 0)
    {
        verinfo=(char*)malloc(versize);
        if (verinfo != NULL)
        {
            memset(verinfo,0,versize);
            status = GetFileVersionInfo(fname,dummy2,versize,verinfo);
            if (status != 0)
            {
                __int64 foo = 0;
                Console::WriteLine(L"Got file version information.");
                status = VerQueryValue(verinfo,TEXT("\\"),(LPVOID *)&fileinfo, &dummy3);
                printf("Size of data returned %d\nSize of structure %d\n",dummy3,sizeof(fileinfo));
                printf("Signature Value: %#X\n",fileinfo.dwSignature);
            }
            else
            {
                Console::WriteLine(L"Failed to get file version information.");
                goto errexit;
            }
        }
        else
        {
            Console::WriteLine(L"Cannot allocate memory for version information buffer.");
            goto errexit;
        }
    }
    else
    {
        Console::WriteLine(L"Cannot read version information of file");
        goto errexit;
    }
    return 0;
errexit: return -1;
}


int main(array<System::String ^> ^args)
{
    int foo;

    Console::WriteLine(L"Hello World");
    foo = checkver(L"C:\\Windows\\System32\\aepic.dll");
    return 0;
}

推荐答案

VerQueryValue返回的指针不是结构体(第3个参数),您应将代码稍作修改为:

VerQueryValue returns a pointer not a struct (the 3rd parameter), you should slightly modify your code to:

 

VS_FIXEDFILEINFO *pInfo;
unsigned int length;
if (VerQueryValue(verInfo, _T("\\"), (void**)&pInfo, &length))
{
	TRACE("Signature=%x\n", pInfo->dwSignature);
}


这篇关于GetFileVersionInfo和VerQueryValue返回奇怪的值...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆