winapi - Can I Write Version Information API For Both CHAR And WCHAR? -
i'm little bit short of reaching goal.
getfileversioninfosize()
working fine along other 2 functions getfileversioninfo()
, verqueryvalue()
. add more features make complete.
i've coded run on wchar
, know making run char
make sense?
is there way around code once , work both?
also, there way enumerate contents of \\stringfileinfo\\lang-codepage\\* ?
dword getfileversioninfo3(const tchar *pszfilepath, std::vector<std::pair<std::wstring, std::wstring>> *lplist) { dword dwsize = 0; byte *pbversioninfo = null; vs_fixedfileinfo *pfileinfo = null; uint pulenfileinfo = 0; dwsize = getfileversioninfosize(pszfilepath, null); if (dwsize == 0) { printf("\nerror in getfileversioninfosize: %d\n", getlasterror()); return 1; } pbversioninfo = new byte[dwsize]; memset(pbversioninfo, '\0', dwsize); if (!getfileversioninfo(pszfilepath, 0, dwsize, pbversioninfo)) { printf("\nerror in getfileversioninfo: %d\n", getlasterror()); delete[] pbversioninfo; return 1; } if (!verqueryvalue(pbversioninfo, text("\\"), (lpvoid*)&pfileinfo, &pulenfileinfo)) { printf("\nerror in verqueryvalue: %d\n", getlasterror()); delete[] pbversioninfo; return 1; } if (!verqueryvalue(pbversioninfo, text("\\varfileinfo\\translation"), (lpvoid*)&lptranslate, &pulenfileinfo)) { printf("\nerror in verqueryvalue: %d\n", getlasterror()); return 1; } std::vector<std::wstring>::iterator itr; std::vector<std::wstring> wlist; wlist.clear(); wlist.push_back(l"filedescription"); wlist.push_back(l"internalname"); wlist.push_back(l"originalfilename"); wlist.push_back(l"companyname"); wlist.push_back(l"fileversion"); wlist.push_back(l"productname"); wlist.push_back(l"productversion"); wlist.push_back(l"legalcopyright"); char fileentry[1024]; (int = 0; < (pulenfileinfo / sizeof(struct langandcodepage)); i++) { sprintf_s(fileentry, 1024, "\\stringfileinfo\\%04x%04x\\", lptranslate[i].wlanguage, lptranslate[i].wcodepage); lplist->push_back(std::pair<std::wstring, std::wstring>(l"file: ", pszfilepath)); std::string s1(fileentry); (itr = wlist.begin(); itr != wlist.end(); itr++) { std::wstring item = *itr; std::wstring wstr; wstr.append(s1.begin(), s1.end()); wstr.append(item); lpvoid lpbuffer = null; uint dwbytes = 0; bool bres = verqueryvalue(pbversioninfo, wstr.c_str(), (lpvoid*)&lpbuffer, &dwbytes); if (!bres) { continue; } lptstr wsresult; wsresult = (lptstr)lpbuffer; lplist->push_back(std::pair<std::wstring, std::wstring>(item, wsresult)); } } return 0; }
since using tchar
, use std:::basic_string<tchar>
instead of std::wstring
match. otherwise, drop tchar
, use wchar
everything.
Comments
Post a Comment