标签:
转载于:http://www.cnblogs.com/procoder/archive/2009/11/13/windows-mobile-wtl-version.html
在Windows Mobile和Wince(Windows Embedded CE)下开发的产品,有时候需要显示当前产品的版本信息。一般来说,版本信息是保存在资源文件里面的,例如下图:
为了保持一致,所有版本信息应该都从资源文件读取,不应该另外硬编码(Hard code)。
下面讲述读取资源文件版本信息的方法:
下面是自己在vs2003下编译通过的版本。
虽然编译时通过了,但是连接还是会出现错误的,下面是解决办法:
在工程属性——配置属性——链接器——输入,“附加依赖项”处添加Version.lib 。
CString GetVersionInfo(HMODULE hLib) { CString version; TCHAR appFilePath[MAX_PATH]; memset(appFilePath, 0, sizeof(char) * MAX_PATH); if (GetModuleFileName(hLib, appFilePath, MAX_PATH)) { DWORD hand = 0; DWORD verLen = GetFileVersionInfoSize(appFilePath,&hand); if (0 < verLen) { TCHAR *verData = (TCHAR *)malloc(verLen); if (verData) { if (GetFileVersionInfoW((LPCWSTR)appFilePath,hand,verLen,verData)) { VS_FIXEDFILEINFO *verInfo; unsigned bufLen; if (VerQueryValueW(verData,(LPWSTR)_T("\\"),(LPVOID *)&verInfo,(PUINT)&bufLen)) { TCHAR numbTxt[8]; memset(numbTxt,0,8); // major _itow(HIWORD(verInfo->dwFileVersionMS),(wchar_t*)numbTxt,10); version = numbTxt; version += _T("."); // minor _itow(LOWORD(verInfo->dwFileVersionMS),(wchar_t*)numbTxt,10); version += numbTxt; version += _T("."); // build _itow(HIWORD(verInfo->dwFileVersionLS),(wchar_t*)numbTxt,10); version += numbTxt; version += _T("."); // revision _itow(LOWORD(verInfo->dwFileVersionLS),(wchar_t*)numbTxt,10); version += numbTxt; } } free(verData); } } } return version; }
这是作者的原版
CString CConfigDialog::GetVersionInfo(HMODULE hLib) { CString version; TCHAR appFilePath[MAX_PATH]; memset(appFilePath, 0, sizeof(char) * MAX_PATH); if (GetModuleFileName(hLib, appFilePath, MAX_PATH)) { DWORD hand = 0; DWORD verLen = GetFileVersionInfoSize(appFilePath,&hand); if (0 < verLen) { TCHAR *verData = (TCHAR *)malloc(verLen); if (verData) { if (GetFileVersionInfoW(appFilePath,hand,verLen,verData)) { VS_FIXEDFILEINFO *verInfo; unsigned bufLen; if (VerQueryValueW(verData,_T("\\"),(LPVOID *)&verInfo,(PUINT)&bufLen)) { TCHAR numbTxt[8]; memset(numbTxt,0,8); // major _itow(HIWORD(verInfo->dwFileVersionMS),numbTxt,10); version = numbTxt; version += _T("."); // minor _itow(LOWORD(verInfo->dwFileVersionMS),numbTxt,10); version += numbTxt; version += _T("."); // build _itow(HIWORD(verInfo->dwFileVersionLS),numbTxt,10); version += numbTxt; version += _T("."); // revision _itow(LOWORD(verInfo->dwFileVersionLS),numbTxt,10); version += numbTxt; } } free(verData); } } } return version; }
HINSTANCE hInst = (HINSTANCE)hModule;
GetVersionInfo(hInst);
完成了,效果如下图:
标签:
原文地址:http://www.cnblogs.com/shmilxu/p/4919444.html