2

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);
user1386966
  • 3,302
  • 13
  • 43
  • 72

2 Answers2

2

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.

johnathan
  • 2,315
  • 13
  • 20
  • thanks! how can I use the GetFileInfoSize ? I see that the parameters are : _In_ LPCTSTR lptstrFilename, _Out_opt_ LPDWORD lpdwHandle ... meaning the first parameter is the path to the dll , and what is the second one? – user1386966 Nov 25 '12 at 15:54
  • the LPDWORD is set to zero when the function runs, and its optional, so i would just pass NULL to it. – johnathan Nov 25 '12 at 15:57
2

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

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • (whispers) there's quite a few, depending on how you want to go about it, you can also go through the shell com interfaces... LOL. – johnathan Mar 08 '13 at 13:54