Reputation: 3402
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);
Upvotes: 2
Views: 2049
Reputation: 597941
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
Upvotes: 2