2012-11-25 85 views
2

我打開一個DLL從system32(shell32.dll) ,我想要收到它的版本。 我該怎麼做?我開始寫它,但只是不知道如何繼續:如何獲取DLL的版本?

我也看到,有像這樣的函數:GetFileVersionSize,有沒有一種方法來使用它們?

這是代碼,如果有人能幫助我繼續,並提供線索,我會很approiciate它

的感謝!

#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); 
+0

出於好奇,爲什麼你需要的dll,你開的版本號? – johnathon

回答

2

Here,這是一個例子,希望對您有所幫助。調用GetFileInfoSize,分配一個這樣大小的緩衝區,然後傳遞您分配給GetFileInfo的緩衝區,然後使用VerQueryValue中傳遞給GetFileInfo的初始化緩衝區。

+0

謝謝!我怎樣才能使用GetFileInfoSize?我看到參數是:_In_ LPCTSTR lptstrFilename, _Out_opt_ LPDWORD lpdwHandle ...意思是第一個參數是dll的路徑,第二個參數是什麼? – user1386966

+0

當函數運行時,LPDWORD被設置爲0,並且它的可選項,所以我只是將NULL傳遞給它。 – johnathon

+0

謝謝!我現在會嘗試:) – user1386966