Earlier on MSDN version information see the introduction of file versions information, looking at the overall complex, has not done. Now need to get the version of the OCX file, so find the next related data, more useful is the vs_fixedfileinfo structure, get this parameter can basically complete the task.
The code is as follows:
1 //typedef struct TAGVS_FIXEDFILEINFO2 //{3 //DWORD dwsignature; /* e.g. 0XFEEF04BD * /4 //DWORD dwstrucversion; /* e.g. 0x00000042 = "0.42" * /5 //DWORD Dwfileversionms; /* e.g. 0x00030075 = "3.75" * /6 //DWORD Dwfileversionls; /* e.g. 0x00000031 = "0.31" * /7 //DWORD Dwproductversionms; /* e.g. 0x00030010 = "3.10" * /8 //DWORD Dwproductversionls; /* e.g. 0x00000031 = "0.31" * /9 //DWORD Dwfileflagsmask; /* = 0x3F for version "0.42" * /Ten //DWORD dwfileflags; /* e.g. Vff_debug | Vff_prerelease * * One //DWORD Dwfileos; /* e.g. VOS_DOS_WINDOWS16 * / A //DWORD Dwfiletype; /* e.g. Vft_driver * / - //DWORD Dwfilesubtype; /* e.g. Vft2_drv_keyboard * / - //DWORD Dwfiledatems; /* e.g. 0 * / the //DWORD Dwfiledatels; /* e.g. 0 * / - //} vs_fixedfileinfo; - { - CharSzappfullpath[_max_path] = {0}; + -GetModuleFileName (Null,szappfullpath,max_path);//get the program module name, full path + A //get version information for the current file atDWORD Dwlen =GetFileVersionInfoSize (szappfullpath,null); - Char*pszappversion =New Char[dwlen+1]; - if(pszappversion) - { -memset (Pszappversion,0,sizeof(Char) * (dwlen+1)); - GetFileVersionInfo (szappfullpath,null,dwlen,pszappversion); in CString strversion; -UINT Nlen (0); toVs_fixedfileinfo *Pfileinfo (NULL); +VerQueryValue (Pszappversion,"\\", (lpvoid*) &pFileInfo,&nlen); - if(Pfileinfo) the { * //Get File version number $Strversion.format ("%d.%d.%d.%d", HiWord (pfileinfo->dwfileversionms),Panax NotoginsengLoWord (pfileinfo->dwfileversionms), -HiWord (pfileinfo->dwfileversionls), theLoWord (pfileinfo->dwfileversionls)); + } A } the}
The basic idea is to get the full path of the executable file, then use the GetFileVersionInfo function to get the version information, and then use the VerQueryValue function to query the version information.
Gets the version information for the Windows executable file (revision number)