+ Reply to Thread
Results 1 to 2 of 2

Thread: Get version of a specified application in WIN32

  1. #1

    Get version of a specified application in WIN32

    Get version of a specified application in WIN32

  2. #2
    Following is an example:

    Code:
    void GetVersionInfoFile(short &nMajorVersion, short &nMinorVersion, short &nMajorBuildNumber, short &nMinorBuildNumber, char szFileName[MAX_PATH])
    {
    	DWORD vSize, vLen, langD ;
    	char fileEntry[256] ;
    	char *versionInfo = NULL ;
    	char buildVersion[MAX_PATH] ;
    	LPVOID retbuf = NULL ;
    
    	char szAppName[MAX_PATH];
    	if(!szFileName)
    	{
    		GetModuleFileName(GetModuleHandle(NULL), szAppName, sizeof(szAppName)) ;
    	}
    	else
    	{
    		strcpy(szAppName, szFileName) ;
    	}
    
    	if(!(vSize = GetFileVersionInfoSize(szAppName, &vLen)))
    	{
    		return ;
    	}
    	versionInfo = (char*)malloc(vSize) ;
    	if(versionInfo && GetFileVersionInfo(szAppName, 0, vSize, versionInfo))
    	{
    		sprintf(fileEntry,"\\VarFileInfo\\Translation") ;
    		BOOL retVal = VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen) ;
    		if (retVal && vLen==4) 
    		{
    			memcpy(&langD,retbuf,4) ;
    			sprintf(fileEntry, "\\StringFileInfo\\%02X%02X%02X%02X\\%s",
    				(langD & 0xff00)>>8,langD & 0xff,(langD & 0xff000000)>>24, 
    				(langD & 0xff0000)>>16, "FileVersion") ;
    		}
    		else
    		{
    			sprintf(fileEntry, "\\StringFileInfo\\%04X04B0\\%s", 
    				GetUserDefaultLangID(), "FileVersion") ;
    		}
    
    		if(VerQueryValue(versionInfo, fileEntry, &retbuf,(UINT *)&vLen))
    		{
    			memset(buildVersion, 0, sizeof(buildVersion)) ;
    			strcpy(buildVersion, (char*)retbuf) ;
    			
    			char* token ;
    			token = strtok(buildVersion, ".") ;
    			if(token)
    			{
    				MajorVersion = atoi(token) ;
    				token = strtok(NULL, ".") ;
    				if(token)
    				{
    					MinorVersion = atoi(token) ;
    					token = strtok(NULL, ".") ;
    					if (token)
    					{
    						MajorBuildNumber = atoi(token) ;
    						token = strtok(NULL, ".") ;
    						if (token)
    						{
    							MinorBuildNumber = atoi(token) ;
    						}
    					}
    				}
    			}
    		}
    	}
    	free(versionInfo) ;
    }
    
    void UseVersionInfo()
    {
            short nMajorVersion, nMinorVersion, nMajorBuildNumber, nMinorBuildNumber ;
    	GetVersionInfoFile(nMajorVersion, nMinorVersion, nMajorBuildNumber, nMinorBuildNumber, "DEVTLDC.DLL") ;
    }
    Note:
    You may need to add Version.lib in the link property.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts