devxlogo

File version information under NT

File version information under NT

Question:
I am using the GetFileVersionInfoSize, GetFileVersionInfo, and VerQueryValue APIs to get the file version of third-party applications. In all cases, GetFileVersionInfoSize returns a large number, but when I query it for StringFileInfo40904B0ProductVersion, sometimes I get nothing. My Visual Basic application and my C++ DLL both return values, but Excel and Visio return nothing. Any thoughts?

Answer:
Not a direct answer, but if you are doing this from multiple envioronments, wouldn’t it be easier to create an ActiveX exe which returns this information, and then use it from all your programs? Write it in either Visual Basic or C++; both do a good job with this kind of stuff. Then you don’t have to worry about what different things you need to do in Excel, Visio, or whatever. Little utility packages like this can be incredibly useful and have a quick payback.

BSTR FAR PASCAL utl_GetFileVersion(LPTSTRpFileName, LPTSTR pInfoToGet){DWORD   dwVerInfoSize;		// Size of version information blockLPSTR   lpVersion;			// String pointer to 'version' textDWORD   dwVerHnd=0;			// An 'ignored' parameter, always '0'UINT    uVersionLen;		// Length of string version informationBOOL    bRetCode;BSTR    bstrVersionInfo;	// Version Info to pass back		// get the size of the version information block	dwVerInfoSize = GetFileVersionInfoSize(pFileName, &dwVerHnd);	if (dwVerInfoSize)	{		LPSTR   lpstrVffInfo;	// pointer to version information block		HANDLE  hMem;		// pointer to allocated memory		HANDLE  hMem2;		// ditto		LPSTR	lpstrVerText;	// text string of info to get			//allocate memory for the version information block		hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);		//load the version information block		lpstrVffInfo  = (char *)GlobalLock(hMem); 		GetFileVersionInfo(pFileName, dwVerHnd, 			dwVerInfoSize, lpstrVffInfo);		hMem2 = GlobalAlloc(GMEM_MOVEABLE, 25 + strlen(pInfoToGet));	lpstrVerText  = (char *)GlobalLock(hMem2);		sprintf(lpstrVerText,"\StringFileInfo\040904B0\%s",pInfoToGet);		// Query the version information block for Product Version		bRetCode = VerQueryValue((LPVOID)lpstrVffInfo,			TEXT(lpstrVerText),			(LPVOID *)&lpVersion,			&uVersionLen);		if(bRetCode)		{				// copy version info into a string VB understands			bstrVersionInfo = SysAllocStringLen(NULL, strlen(lpVersion)+1);			memset(bstrVersionInfo, 0, strlen(lpVersion)+1);			memcpy(bstrVersionInfo, lpVersion, strlen(lpVersion));			return (bstrVersionInfo);		}		else		{			return (0);		}	}	else		return (0);  }

See also  How AI Art Generators Can Save Time and Money for Startups
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist