获取版本:
- CString GetFileVersion(char* FileName)
- {
- int iVerInfoSize;
- char *pBuf;
- CString asVer="";
- VS_FIXEDFILEINFO *pVsInfo;
- unsigned int iFileInfoSize = sizeof( VS_FIXEDFILEINFO );
- iVerInfoSize = GetFileVersionInfoSize(FileName,NULL);
- if(iVerInfoSize!= 0)
- {
- pBuf = new char[iVerInfoSize];
- if(GetFileVersionInfo(FileName,0, iVerInfoSize, pBuf ) )
- {
- if(VerQueryValue(pBuf, "//",(void **)&pVsInfo,&iFileInfoSize))
- {
- asVer.Format("%d.%d.%d.%d",HIWORD(pVsInfo->dwFileVersionMS),LOWORD(pVsInfo->dwFileVersionMS),HIWORD(pVsInfo->dwFileVersionLS),LOWORD(pVsInfo->dwFileVersionLS));
- }
- }
- delete pBuf;
- }
- return asVer;
- }
获取路径:
- CString GetCurrentAppDirectory()
- {
- char szFile[MAX_PATH];
- char szPath[MAX_PATH];
- GetModuleFileName(NULL,szFile,MAX_PATH);
- size_t i;
- for(i=strlen(szFile)-1; i>0 && szFile[i]!='//'; i--);
- szFile[i]='/0';
- strcpy(szPath,szFile);
- return (szPath);
- }
获取修改时间:
- CString GetModifyTime(CString appname)
- {
- WIN32_FIND_DATA ffd ;
- HANDLE hFind = FindFirstFile(appname,&ffd);
- SYSTEMTIME stUTC, stLocal;
- FileTimeToSystemTime(&(ffd.ftLastWriteTime), &stUTC);
- SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
- CString strTmp;
- strTmp.Format("%d-%d-%d,%d:%d", stLocal.wYear,stLocal.wMonth,stLocal.wDay,stLocal.wHour,stLocal.wMinute);
- //--
- return strTmp;
- }
转帖:http://blog.csdn.net/lanmanck/article/details/3901590
==============================================================================================
上面那个有问题,下面这个成功:
CString CMFCVLCDlg::GetFileVer()
{
char cPath[200],szVersionBuffer[200];
DWORD dwHandle,InfoSize;
CString strVersion;
::GetModuleFileName(NULL,cPath,sizeof(cPath)); //首先获得版本信息资源的长度
InfoSize = GetFileVersionInfoSize(cPath,&dwHandle); //将版本信息资源读入缓冲区
if(InfoSize==0) return _T("None VerSion Supprot");
char *InfoBuf = new char[InfoSize];
GetFileVersionInfo(cPath,0,InfoSize,InfoBuf); //获得生成文件使用的代码页及文件版本
unsigned int cbTranslate = 0;
struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
VerQueryValue(InfoBuf, TEXT("\\VarFileInfo\\Translation"),(LPVOID*)&lpTranslate,&cbTranslate);
// Read the file description for each language and code page.
for( int i=0; i < (cbTranslate/sizeof(struct LANGANDCODEPAGE)); i++ )
{
char SubBlock[200];
wsprintf( SubBlock,
TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"),
lpTranslate[i].wLanguage,
lpTranslate[i].wCodePage);
void *lpBuffer=NULL;
unsigned int dwBytes=0;
VerQueryValue(InfoBuf,
SubBlock,
&lpBuffer,
&dwBytes);
CString strTemp=(char *)lpBuffer;
strVersion+=strTemp;
}
return strVersion;
}
转帖:http://www.cnblogs.com/wxlzhizu/archive/2009/12/09/1620009.html