简体   繁体   中英

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. 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?

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.

There is actually two ways to get a DLL's version. Many system DLLs export a DllGetVersion() function. For DLLs that do not, you have to fall back to GetFileVersionInfo() and related functions. The following article shows you an example of using both:

Determining the version number of a DLL or Executable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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