简体   繁体   English

如何获取 DLL 的版本?

[英]how to get the Version of a DLL?

I'm opening a DLL from system32 (shell32.dll ) and I want to receive it's version.我正在从 system32 (shell32.dll) 打开一个 DLL,我想接收它的版本。 How Can I do it?我该怎么做? I started writing it , but just don't know how to continue :我开始写它,但只是不知道如何继续:

I also saw that there are functions like : GetFileVersionSize , is there a way to use them?我还看到有像这样的函数: GetFileVersionSize ,有没有办法使用它们?

this is the code , If anyone can help me continue it and give a clue , I would really approiciate it这是代码,如果有人能帮我继续它并提供线索,我真的很乐意

thanks!谢谢!

#define PATH    "C:\\Users\\rachel\\Desktop\\shell32.dll"

PVERSION dll_getVersion(PCHAR pDllPath)
{
 PVERSION       version             =   NULL;
 HINSTANCE      dllLoad             =   NULL;
 HRSRC          resourceHandle      =   NULL;
 HGLOBAL            loadResourceHandle  =   NULL;
 LPVOID         lockResourceHande   =   NULL;
 DWORD          sizeOfResource      =   0;

 //LPCTSTR  lptstrFilename = NULL;
 //DWORD    dfHandle = 0;
 //DWORD dwLen = 0;
 //LPVOID   lpData = NULL;
 //BOOL test = FALSE;

 //DWORD fileVersionSize = 0;
 //unsigned long u = 0;
 //fileVersionSize = GetFileVersionInfoSize(PATH , &u);

 //test = GetFileVersionInfo(PATH, dfHandle , dwLen ,lpData);



if (NULL == pDllPath)
{
    printf("error #1 : dllPath is invalid \n");
    return version;
}

version = (PVERSION)calloc(1,sizeof(VERSION));
if (NULL == version)
{
    printf("the allocation failed \n");
    return version;
}

//opening the dll using the path */
dllLoad = LoadLibrary(pDllPath);
if (NULL == dllLoad)
{
    printf("failed to load the dll ! \n");
    printf("the last error is : %d\n" , GetLastError());
    free(version);
    version = NULL;
    return version;
}

resourceHandle          =    FindResource(dllLoad ,MAKEINTRESOURCE(16) , RT_VERSION);
if (NULL == resourceHandle)
{
    printf("problem with find resource!!!! \n");
    return NULL;
}
loadResourceHandle      =    LoadResource(dllLoad , resourceHandle);

if (NULL == loadResourceHandle)
{
    printf("problem with load resource function! \n");
    return NULL;
}

lockResourceHande = LockResource(loadResourceHandle);
if (NULL == lockResourceHande)
{
    printf("error in lock resource function \n");
    return NULL;
}

sizeOfResource = SizeofResource(dllLoad, resourceHandle);

Here , an example for you, hope this helps. 在这里,给你一个例子,希望对你有所帮助。 Call GetFileInfoSize, allocate a buffer of that size , then pass the buffer that you allocated to GetFileInfo, then use the initialized buffer that you passed into GetFileInfo, in VerQueryValue.调用 GetFileInfoSize,分配该大小的缓冲区,然后将分配给 GetFileInfo 的缓冲区传递给 VerQueryValue,然后使用传递给 GetFileInfo 的初始化缓冲区。

There is actually two ways to get a DLL's version.实际上有两种方法可以获取 DLL 的版本。 Many system DLLs export a DllGetVersion() function.许多系统 DLL 导出DllGetVersion()函数。 For DLLs that do not, you have to fall back to GetFileVersionInfo() and related functions.对于没有的 DLL,您必须退回到GetFileVersionInfo()和相关函数。 The following article shows you an example of using both:以下文章向您展示了使用两者的示例:

Determining the version number of a DLL or Executable 确定 DLL 或可执行文件的版本号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM