int main(int argc, char **argv) { LPSTR szFileList; char **index, *sz; int retcode, i, cc; DWORD dwVerInfoSize; DWORD dwVerHnd; char szFullPath[PATH_MAX]; #ifdef WIN32 char *ptr; #else HFILE hfile; OFSTRUCT ofs; #endif HANDLE hMem; /* handle to mem alloc'ed */ if (argc < 3) return 0; /* Exits if not proper number of arguments */ hZUF = GlobalAlloc( GPTR, (DWORD)sizeof(ZIPUSERFUNCTIONS)); if (!hZUF) { return 0; } lpZipUserFunctions = (LPZIPUSERFUNCTIONS)GlobalLock(hZUF); if (!lpZipUserFunctions) { GlobalFree(hZUF); return 0; } lpZipUserFunctions->print = DummyPrint; lpZipUserFunctions->password = DummyPassword; lpZipUserFunctions->comment = DummyComment; /* Let's go find the dll */ #ifdef WIN32 if (SearchPath( NULL, /* address of search path */ ZIP_DLL_NAME, /* address of filename */ NULL, /* address of extension */ PATH_MAX, /* size, in characters, of buffer */ szFullPath, /* address of buffer for found filename */ &ptr /* address of pointer to file component */ ) == 0) #else hfile = OpenFile(ZIP_DLL_NAME, &ofs, OF_SEARCH); if (hfile == HFILE_ERROR) #endif { char str[256]; wsprintf (str, DLL_WARNING, ZIP_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } #ifndef WIN32 else lstrcpy(szFullPath, ofs.szPathName); _lclose(hfile); #endif /* Now we'll check the zip dll version information */ dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd); if (dwVerInfoSize) { BOOL fRet, fRetName; char str[256]; LPSTR lpstrVffInfo; /* Pointer to block to hold info */ LPSTR lszVer = NULL; LPSTR lszVerName = NULL; UINT cchVer = 0; /* Get a block big enough to hold the version information */ hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize); lpstrVffInfo = GlobalLock(hMem); /* Get the version information */ GetFileVersionInfo(szFullPath, 0L, dwVerInfoSize, lpstrVffInfo); fRet = VerQueryValue(lpstrVffInfo, TEXT("\\StringFileInfo\\040904E4\\FileVersion"), (LPVOID)&lszVer, &cchVer); fRetName = VerQueryValue(lpstrVffInfo, TEXT("\\StringFileInfo\\040904E4\\CompanyName"), (LPVOID)&lszVerName, &cchVer); if (!fRet || !fRetName || (lstrcmpi(lszVer, ZIP_DLL_VERSION) != 0) || (lstrcmpi(lszVerName, COMPANY_NAME) != 0)) { wsprintf (str, DLL_VERSION_WARNING, ZIP_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } /* free memory */ GlobalUnlock(hMem); GlobalFree(hMem); } else { char str[256]; wsprintf (str, DLL_VERSION_WARNING, ZIP_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } /* Okay, now we know that the dll exists, and has the proper version * information in it. We can go ahead and load it. */ hZipDll = LoadLibrary(ZIP_DLL_NAME); #ifndef WIN32 if (hZipDll > HINSTANCE_ERROR) #else if (hZipDll != NULL) #endif { (_DLL_ZIP)ZipArchive = (_DLL_ZIP)GetProcAddress(hZipDll, "ZpArchive"); (ZIPSETOPTIONS)ZipSetOptions = (ZIPSETOPTIONS)GetProcAddress(hZipDll, "ZpSetOptions"); if (!ZipArchive || !ZipSetOptions) { char str[256]; wsprintf (str, "Could not get entry point to %s", ZIP_DLL_NAME); MessageBox((HWND)NULL, str, "Info-ZIP Example", MB_ICONSTOP | MB_OK); FreeUpMemory(); return 0; } } else { char str[256]; wsprintf (str, "Could not load %s", ZIP_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } (_ZIP_USER_FUNCTIONS)ZipInit = (_ZIP_USER_FUNCTIONS)GetProcAddress(hZipDll, "ZpInit"); if (!ZipInit) { printf("Cannot get address of ZpInit in Zip dll. Terminating..."); FreeLibrary(hZipDll); FreeUpMemory(); return 0; } if (!(*ZipInit)(lpZipUserFunctions)) { printf("Application functions not set up properly. Terminating..."); FreeLibrary(hZipDll); FreeUpMemory(); return 0; } /* Here is where the action starts */ ZpOpt.fSuffix = FALSE; /* include suffixes (not yet implemented) */ ZpOpt.fEncrypt = FALSE; /* true if encryption wanted */ ZpOpt.fSystem = FALSE; /* true to include system/hidden files */ ZpOpt.fVolume = FALSE; /* true if storing volume label */ ZpOpt.fExtra = FALSE; /* true if including extra attributes */ ZpOpt.fNoDirEntries = FALSE; /* true if ignoring directory entries */ ZpOpt.fVerbose = FALSE; /* true if full messages wanted */ ZpOpt.fQuiet = FALSE; /* true if minimum messages wanted */ ZpOpt.fCRLF_LF = FALSE; /* true if translate CR/LF to LF */ ZpOpt.fLF_CRLF = FALSE; /* true if translate LF to CR/LF */ ZpOpt.fJunkDir = FALSE; /* true if junking directory names */ ZpOpt.fGrow = FALSE; /* true if allow appending to zip file */ ZpOpt.fForce = FALSE; /* true if making entries using DOS names */ ZpOpt.fMove = FALSE; /* true if deleting files added or updated */ ZpOpt.fUpdate = FALSE; /* true if updating zip file--overwrite only if newer */ ZpOpt.fFreshen = FALSE; /* true if freshening zip file--overwrite only */ ZpOpt.fJunkSFX = FALSE; /* true if junking sfx prefix*/ ZpOpt.fLatestTime = FALSE; /* true if setting zip file time to time of latest file in archive */ ZpOpt.fComment = FALSE; /* true if putting comment in zip file */ ZpOpt.fOffsets = FALSE; /* true if updating archive offsets for sfx files */ ZpOpt.fDeleteEntries = FALSE; /* true if deleting files from archive */ ZpOpt.fRecurse = 0; /* subdir recursing mode: 1 = "-r", 2 = "-R" */ ZpOpt.fRepair = 0; /* archive repair mode: 1 = "-F", 2 = "-FF" */ ZpOpt.Date = NULL; /* Not using, set to NULL pointer */ getcwd(szFullPath, PATH_MAX); /* Set directory to current directory */ ZpOpt.szRootDir = szFullPath; ZpZCL.argc = argc - 2; /* number of files to archive - adjust for the actual number of file names to be added */ ZpZCL.lpszZipFN = argv[1]; /* archive to be created/updated */ /* Copy over the appropriate portions of argv, basically stripping out argv[0] (name of the executable) and argv[1] (name of the archive file) */ hFileList = GlobalAlloc( GPTR, 0x10000L); if ( hFileList ) { szFileList = (char far *)GlobalLock(hFileList); } index = (char **)szFileList; cc = (sizeof(char *) * ZpZCL.argc); sz = szFileList + cc; for (i = 0; i < ZpZCL.argc; i++) { cc = lstrlen(argv[i+2]); lstrcpy(sz, argv[i+2]); index[i] = sz; sz += (cc + 1); } ZpZCL.FNV = (char **)szFileList; /* list of files to archive */ /* Set the options */ ZipSetOptions(&ZpOpt); /* Go zip 'em up */ retcode = ZipArchive(ZpZCL); if (retcode != 0) printf("Error in archiving\n"); GlobalUnlock(hFileList); GlobalFree(hFileList); FreeUpMemory(); FreeLibrary(hZipDll); return 1; }
LONG CFBPanel::OnDblclk(HWND hwndCPl, UINT /*uAppNum*/, LONG /*lData*/) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Create the dialog box using the parent window handle CFBDialog dlg(CWnd::FromHandle(hwndCPl)); try { // Check if Firebird is installed by reading the registry HKEY hkey; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_KEY_ROOT_INSTANCES, 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { char rootpath[MAX_PATH - 2]; DWORD buffer_size = sizeof(rootpath); if (RegQueryValueEx(hkey, FB_DEFAULT_INSTANCE, NULL, NULL, LPBYTE(rootpath), &buffer_size) == ERROR_SUCCESS) { PathAddBackslash(rootpath); dlg.m_Root_Path = rootpath; } RegCloseKey(hkey); dlg.m_FB_Version = "not known"; CString afilename = dlg.m_Root_Path + "bin\\gbak.exe"; buffer_size = GetFileVersionInfoSize( (LPCTSTR) afilename, 0); void* VersionInfo = new char [buffer_size]; void* ProductVersion = 0; void* SpecialBuild = 0; void* PrivateBuild = 0; UINT ValueSize; if ( GetFileVersionInfo((LPCTSTR) afilename, 0, buffer_size, VersionInfo) ) { VerQueryValue( VersionInfo, "\\StringFileInfo\\040904E4\\ProductVersion", &ProductVersion, &ValueSize); if (ValueSize) { dlg.m_FB_Version = "Version "; dlg.m_FB_Version += (char*) ProductVersion; } VerQueryValue( VersionInfo, "\\StringFileInfo\\040904E4\\SpecialBuild", &SpecialBuild, &ValueSize); if (ValueSize) { dlg.m_FB_Version += " "; dlg.m_FB_Version += (char*) SpecialBuild; } VerQueryValue( VersionInfo, "\\StringFileInfo\\040904E4\\PrivateBuild", &PrivateBuild, &ValueSize); if (ValueSize) { dlg.m_FB_Version += " "; dlg.m_FB_Version += (char*) PrivateBuild; } /**/ } delete[] (char*) VersionInfo; // Show the dialog box if (dlg.DoModal() != IDOK) return 0; } } catch ( ... ) { //raise an error dlg.MessageBox("Firebird does not appear to be installed correctly.", "Installation Error", MB_OK); } return 0; }
static void test_VerQueryValue(void) { static const char * const value_name[] = { "Product", "CompanyName", "FileDescription", "Internal", "ProductVersion", "InternalName", "File", "LegalCopyright", "FileVersion", "Legal", "OriginalFilename", "ProductName", "Company", "Original" }; char *ver, *p; UINT len, ret, translation, i; char buf[MAX_PATH]; ret = GetModuleFileName(NULL, buf, sizeof(buf)); assert(ret); SetLastError(0xdeadbeef); len = GetFileVersionInfoSize(buf, NULL); ok(len, "GetFileVersionInfoSize(%s) error %u\n", buf, GetLastError()); ver = HeapAlloc(GetProcessHeap(), 0, len); assert(ver); SetLastError(0xdeadbeef); ret = GetFileVersionInfo(buf, 0, len, ver); ok(ret, "GetFileVersionInfo error %u\n", GetLastError()); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValue(ver, "\\VarFileInfo\\Translation", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); ok(len == 4, "VerQueryValue returned %u, expected 4\n", len); translation = *(UINT *)p; translation = MAKELONG(HIWORD(translation), LOWORD(translation)); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValue(ver, "String", (LPVOID*)&p, &len); ok(!ret, "VerQueryValue should fail\n"); ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND || GetLastError() == 0xdeadbeef /* NT4, W2K */, "VerQueryValue returned %u\n", GetLastError()); ok(p == (char *)0xdeadbeef, "expected 0xdeadbeef got %p\n", p); ok(len == 0, "expected 0 got %x\n", len); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValue(ver, "StringFileInfo", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValue(ver, "\\StringFileInfo", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValue(ver, "\\\\StringFileInfo", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValue(ver, "\\StringFileInfo\\\\", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); sprintf(buf, "\\StringFileInfo\\%08x", translation); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValue(ver, buf, (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); for (i = 0; i < sizeof(value_name)/sizeof(value_name[0]); i++) { sprintf(buf, "\\StringFileInfo\\%08x\\%s", translation, value_name[i]); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValue(ver, buf, (LPVOID*)&p, &len); ok(ret, "VerQueryValue(%s) error %u\n", buf, GetLastError()); ok(len == strlen(value_name[i]) + 1, "VerQueryValue returned %u\n", len); ok(!strcmp(value_name[i], p), "expected \"%s\", got \"%s\"\n", value_name[i], p); /* test partial value names */ len = lstrlen(buf); buf[len - 2] = 0; p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValue(ver, buf, (LPVOID*)&p, &len); ok(!ret, "VerQueryValue(%s) succeeded\n", buf); ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND || GetLastError() == 0xdeadbeef /* NT4, W2K */, "VerQueryValue returned %u\n", GetLastError()); ok(p == (char *)0xdeadbeef, "expected 0xdeadbeef got %p\n", p); ok(len == 0, "expected 0 or 0xbeef, got %x\n", len); } HeapFree(GetProcessHeap(), 0, ver); }
BOOL CPlugins::Register(const CString& sPath) { Clear(); DWORD nSucceeded = 0, nFailed = 0; LPCTSTR szParam = #if defined(_MSC_VER) && (_MSC_VER >= 1500) // No VS2005 AfxGetPerUserRegistration() ? _T("/RegServerPerUser") : #endif _T("/RegServer"); CFileFind finder; BOOL bWorking = finder.FindFile( sPath + _T("\\*.*") ); // .DLLs +.EXEs while ( bWorking ) { bWorking = finder.FindNextFile(); const CString strPath = finder.GetFilePath(); const CString strName = finder.GetFileName(); const CString strExt = PathFindExtension( strName ); if ( strExt.CompareNoCase( _T(".dll") ) == 0 ) { if ( strName == _T("WebHook.dll") && ! Settings.Downloads.WebHookEnable ) continue; // Skip WebHook Integration if ( HINSTANCE hDll = LoadLibrary( strPath ) ) { HRESULT hr = S_FALSE; #if defined(_MSC_VER) && (_MSC_VER >= 1500) // Legacy VS2005 No AfxGetPerUserRegistration HRESULT (WINAPI *pfnDllInstall)(BOOL bInstall, LPCWSTR pszCmdLine); (FARPROC&)pfnDllInstall = GetProcAddress( hDll, "DllInstall" ); if ( pfnDllInstall && AfxGetPerUserRegistration() ) { hr = pfnDllInstall( TRUE, L"user" ); } else #endif { HRESULT (WINAPI *pfnDllRegisterServer)(void); (FARPROC&)pfnDllRegisterServer = GetProcAddress( hDll, "DllRegisterServer" ); if ( pfnDllRegisterServer ) hr = pfnDllRegisterServer(); } if ( hr == S_OK ) { nSucceeded++; theApp.Message( MSG_NOTICE, _T("Registered plugin: %s"), strName ); } else if ( FAILED( hr ) ) { nFailed++; theApp.Message( MSG_ERROR, _T("Failed to register plugin: %s : 0x%08x"), strName, hr ); } FreeLibrary( hDll ); } } else if ( strExt.CompareNoCase( _T(".exe") ) == 0 ) { DWORD dwSize = GetFileVersionInfoSize( sPath, &dwSize ); CAutoVectorPtr< BYTE > pBuffer( new BYTE[ dwSize ] ); if ( pBuffer && GetFileVersionInfo( sPath, NULL, dwSize, pBuffer ) ) { LPCWSTR pValue = NULL; if ( VerQueryValue( pBuffer, _T("\\StringFileInfo\\000004b0\\SpecialBuild"), (void**)&pValue, (UINT*)&dwSize ) && pValue && dwSize && _wcsicmp( pValue, _T("plugin") ) == 0 ) { SHELLEXECUTEINFO sei = { sizeof( SHELLEXECUTEINFO ), SEE_MASK_NOCLOSEPROCESS, NULL, NULL, strPath, szParam, sPath, SW_HIDE }; DWORD dwError = ERROR_INVALID_FUNCTION; if ( ShellExecuteEx( &sei ) ) { WaitForSingleObject( sei.hProcess, INFINITE ); GetExitCodeProcess( sei.hProcess, &dwError ); CloseHandle( sei.hProcess ); } else dwError = GetLastError(); if ( dwError == ERROR_SUCCESS ) { nSucceeded++; theApp.Message( MSG_NOTICE, _T("Registered plugin: %s"), strName ); } else { nFailed++; theApp.Message( MSG_ERROR, _T("Failed to register plugin: %s : 0x%08x"), strName, dwError ); } } } } } return ( nSucceeded != 0 && nFailed == 0 ); }
void LoadLangDll() { if ((g_langid != g_ShellCache.GetLangID())&&((g_langTimeout == 0)||(g_langTimeout < GetTickCount()))) { g_langid = g_ShellCache.GetLangID(); DWORD langId = g_langid; TCHAR langDll[MAX_PATH*4]; HINSTANCE hInst = NULL; TCHAR langdir[MAX_PATH] = {0}; char langdirA[MAX_PATH] = {0}; if (GetModuleFileName(g_hmodThisDll, langdir, MAX_PATH)==0) return; if (GetModuleFileNameA(g_hmodThisDll, langdirA, MAX_PATH)==0) return; TCHAR * dirpoint = _tcsrchr(langdir, '\\'); char * dirpointA = strrchr(langdirA, '\\'); if (dirpoint) *dirpoint = 0; if (dirpointA) *dirpointA = 0; dirpoint = _tcsrchr(langdir, '\\'); dirpointA = strrchr(langdirA, '\\'); if (dirpoint) *dirpoint = 0; if (dirpointA) *dirpointA = 0; strcat_s(langdirA, MAX_PATH, "\\Languages"); // bindtextdomain ("subversion", langdirA); do { _stprintf_s(langDll, MAX_PATH*4, _T("%s\\Languages\\TortoiseProc%d.dll"), langdir, langId); BOOL versionmatch = TRUE; struct TRANSARRAY { WORD wLanguageID; WORD wCharacterSet; }; DWORD dwReserved,dwBufferSize; dwBufferSize = GetFileVersionInfoSize((LPTSTR)langDll,&dwReserved); if (dwBufferSize > 0) { LPVOID pBuffer = (void*) malloc(dwBufferSize); if (pBuffer != (void*) NULL) { UINT nInfoSize = 0, nFixedLength = 0; LPSTR lpVersion = NULL; VOID* lpFixedPointer; TRANSARRAY* lpTransArray; TCHAR strLangProduktVersion[MAX_PATH]; if (GetFileVersionInfo((LPTSTR)langDll, dwReserved, dwBufferSize, pBuffer)) { // Query the current language if (VerQueryValue( pBuffer, _T("\\VarFileInfo\\Translation"), &lpFixedPointer, &nFixedLength)) { lpTransArray = (TRANSARRAY*) lpFixedPointer; _stprintf_s(strLangProduktVersion, MAX_PATH, _T("\\StringFileInfo\\%04x%04x\\ProductVersion"), lpTransArray[0].wLanguageID, lpTransArray[0].wCharacterSet); if (VerQueryValue(pBuffer, (LPTSTR)strLangProduktVersion, (LPVOID *)&lpVersion, &nInfoSize)) { // versionmatch = (_tcscmp((LPCTSTR)lpVersion, _T(STRPRODUCTVER)) == 0); } } } free(pBuffer); } // if (pBuffer != (void*) NULL) } // if (dwBufferSize > 0) else versionmatch = FALSE; if (versionmatch) hInst = LoadLibrary(langDll); if (hInst != NULL) { if (g_hResInst != g_hmodThisDll) FreeLibrary(g_hResInst); g_hResInst = hInst; } else { DWORD lid = SUBLANGID(langId); lid--; if (lid > 0) { langId = MAKELANGID(PRIMARYLANGID(langId), lid); } else langId = 0; } } while ((hInst == NULL) && (langId != 0)); if (hInst == NULL) { // either the dll for the selected language is not present, or // it is the wrong version. // fall back to English and set a timeout so we don't retry // to load the language dll too often if (g_hResInst != g_hmodThisDll) FreeLibrary(g_hResInst); g_hResInst = g_hmodThisDll; g_langid = 1033; // set a timeout of 10 seconds if (g_ShellCache.GetLangID() != 1033) g_langTimeout = GetTickCount() + 10000; } else g_langTimeout = 0; } // if (g_langid != g_ShellCache.GetLangID()) }
XP_HLIB LoadRealPlugin(char * mimetype) { if(!mimetype || !strlen(mimetype)) return NULL; #ifdef XP_WIN BOOL bDone = FALSE; WIN32_FIND_DATA ffdataStruct; char szPath[_MAX_PATH]; char szFileName[_MAX_PATH]; // DebugBreak(); GetPluginsDir(szPath, _MAX_PATH); if(logger) { char msg[512]; sprintf(msg, "LoadRealPlugin Path: %s\r\n", szPath); logger->logMessage(msg); } strcpy(szFileName, szPath); std::vector<std::string> directories; directories.push_back(szFileName); directories.push_back("C:\\Windows\\System32\\Macromed\\Flash"); directories.push_back("C:\\Windows\\SysWOW64\\Macromed\\Flash"); for (size_t i = 0; i < directories.size(); ++i) { std::string search_path = directories[i]; search_path = search_path.append("\\np*.dll"); HANDLE handle = FindFirstFile(search_path.c_str(), &ffdataStruct); if(handle == INVALID_HANDLE_VALUE) { FindClose(handle); continue; } DWORD versize = 0L; DWORD zero = 0L; char * verbuf = NULL; do { std::string cur_file = directories[i]; cur_file = cur_file.append("\\"); cur_file = cur_file.append(ffdataStruct.cFileName); if(!(ffdataStruct. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strstr(cur_file.c_str(), "npspy.dll") == NULL) { versize = GetFileVersionInfoSize(cur_file.c_str(), &zero); if (versize > 0) verbuf = new char[versize]; else continue; if(!verbuf) continue; GetFileVersionInfo(cur_file.c_str(), NULL, versize, verbuf); char *mimetypes = NULL; UINT len = 0; if(!VerQueryValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType", (void **)&mimetypes, &len) || !mimetypes || !len) { delete [] verbuf; continue; } // browse through a string of mimetypes mimetypes[len] = '\0'; char * type = mimetypes; BOOL more = TRUE; while(more) { char * p = strchr(type, '|'); if(p) *p = '\0'; else more = FALSE; if(0 == _stricmp(mimetype, type)) { // this is it! delete [] verbuf; FindClose(handle); HINSTANCE hLib = LoadLibrary(cur_file.c_str()); return hLib; } type = p; type++; } delete [] verbuf; } } while(FindNextFile(handle, &ffdataStruct)); FindClose(handle); } #endif #ifdef XP_UNIX // Implement UNIX version #endif #ifdef XP_MAC // Implement Mac version #endif return NULL; }
int CCrashHandler::Init( LPCTSTR lpcszAppName, LPCTSTR lpcszAppVersion, LPCTSTR lpcszCrashSenderPath, LPGETLOGFILE lpfnCallback, LPCTSTR lpcszTo, LPCTSTR lpcszSubject, LPCTSTR lpcszUrl, UINT (*puPriorities)[3]) { crSetErrorMsg(_T("Unspecified error.")); // save user supplied callback if (lpfnCallback) m_lpfnCallback = lpfnCallback; // Get handle to the EXE module used to create this process HMODULE hExeModule = GetModuleHandle(NULL); if(hExeModule==NULL) { ATLASSERT(hExeModule!=NULL); crSetErrorMsg(_T("Couldn't get module handle for the executable.")); return 1; } TCHAR szExeName[_MAX_PATH]; DWORD dwLength = GetModuleFileName(hExeModule, szExeName, _MAX_PATH); if(dwLength==0) { // Couldn't get the name of EXE that was used to create current process ATLASSERT(0); crSetErrorMsg(_T("Couldn't get the name of EXE that was used to create current process.")); return 1; } // Save EXE image name m_sImageName = CString(szExeName, dwLength); // Save application name m_sAppName = lpcszAppName; // If no app name provided, use the default (EXE name) if(m_sAppName.IsEmpty()) m_sAppName = CUtility::getAppName(); // Save app version m_sAppVersion = lpcszAppVersion; // If no app version provided, use the default (EXE product version) if(m_sAppVersion.IsEmpty()) { DWORD dwBuffSize = GetFileVersionInfoSize(szExeName, 0); LPBYTE pBuff = new BYTE[dwBuffSize]; if(0!=GetFileVersionInfo(szExeName, 0, dwBuffSize, pBuff)) { VS_FIXEDFILEINFO* fi = NULL; UINT uLen = 0; VerQueryValue(pBuff, _T("\\"), (LPVOID*)&fi, &uLen); WORD dwVerMajor = (WORD)(fi->dwProductVersionMS>>16); WORD dwVerMinor = (WORD)(fi->dwProductVersionMS&0xFF); WORD dwPatchLevel = (WORD)(fi->dwProductVersionLS>>16); WORD dwVerBuild = (WORD)(fi->dwProductVersionLS&0xFF); m_sAppVersion.Format(_T("%u.%u.%u.%u"), dwVerMajor, dwVerMinor, dwPatchLevel, dwVerBuild); }
// ================================================================================= // Version // ================================================================================= void GameMemory::FetchVersion() { // One-Time-Only if (Version != NULL) return; // Game EXE char* sVersionFile = Memory::GetModulePath((HMODULE) Base); if (sVersionFile == NULL) { printf("GameMemory::FetchVersion failed [Memory::GetModulePath returned 0]\n"); return; } // Version Info Size DWORD dwVersionInfoSize = GetFileVersionInfoSize(sVersionFile, NULL); if (dwVersionInfoSize == NULL) { printf("GameMemory::FetchVersion failed! [GetFileVersionInfoSize returned 0]\n"); // Cleanup free(sVersionFile); return; } // Version Info VS_FIXEDFILEINFO* pFileInfo = (VS_FIXEDFILEINFO*) new BYTE[dwVersionInfoSize]; DWORD dwVersionHandle = NULL; if (!GetFileVersionInfo(sVersionFile, dwVersionHandle, dwVersionInfoSize, pFileInfo)) { printf("GameMemory::FetchVersion failed! [GetFileVersionInfo failed]\n"); // Cleanup free(sVersionFile); delete[] pFileInfo; return; } // Query UINT uiFileInfoLength = 0; VS_FIXEDFILEINFO* pVersionInfo = NULL; if (!VerQueryValue(pFileInfo, "\\", (LPVOID*) &pVersionInfo, &uiFileInfoLength) || uiFileInfoLength == 0) { printf("GameMemory::FetchVersion failed! [VerQueryValue failed]\n"); // Cleanup free(sVersionFile); delete[] pFileInfo; if (pVersionInfo != NULL) delete pVersionInfo; return; } // Signature if (pVersionInfo->dwSignature != 0xFEEF04BD) { printf("GameMemory::FetchVersion failed! [Signature mismatch, got %X]\n", pVersionInfo->dwSignature); // Cleanup free(sVersionFile); delete[] pFileInfo; if (pVersionInfo != NULL) delete pVersionInfo; return; } // Build Version String Version = new char[128]; sprintf(Version, "%d.%d.%d.%d", (pVersionInfo->dwFileVersionMS >> 16) & 0xffff, (pVersionInfo->dwFileVersionMS >> 0) & 0xffff, (pVersionInfo->dwFileVersionLS >> 16) & 0xffff, (pVersionInfo->dwFileVersionLS >> 0) & 0xffff); // Cleanup free(sVersionFile); delete[] pFileInfo; }
int main(int argc, char **argv) { int exfc, infc; char **exfv, **infv; char *x_opt; DWORD dwVerInfoSize; DWORD dwVerHnd; char szFullPath[_MAX_PATH]; int retcode; #ifdef WIN32 char *ptr; #else HFILE hfile; OFSTRUCT ofs; #endif HANDLE hMem; /* handle to mem alloc'ed */ if (argc < 2) /* We must have an archive to unzip */ { printf("usage: %s <zipfile> [entry1 [entry2 [...]]] [-x xentry1 [...]]", "example"); return 0; } hDCL = GlobalAlloc( GPTR, (DWORD)sizeof(DCL)); if (!hDCL) { return 0; } lpDCL = (LPDCL)GlobalLock(hDCL); if (!lpDCL) { GlobalFree(hDCL); return 0; } hUF = GlobalAlloc( GPTR, (DWORD)sizeof(USERFUNCTIONS)); if (!hUF) { GlobalUnlock(hDCL); GlobalFree(hDCL); return 0; } lpUserFunctions = (LPUSERFUNCTIONS)GlobalLock(hUF); if (!lpUserFunctions) { GlobalUnlock(hDCL); GlobalFree(hDCL); GlobalFree(hUF); return 0; } lpUserFunctions->password = password; lpUserFunctions->print = DisplayBuf; lpUserFunctions->sound = NULL; lpUserFunctions->replace = GetReplaceDlgRetVal; lpUserFunctions->SendApplicationMessage = ReceiveDllMessage; /* First we go look for the unzip dll */ #ifdef WIN32 if (SearchPath( NULL, /* address of search path */ UNZ_DLL_NAME, /* address of filename */ NULL, /* address of extension */ _MAX_PATH, /* size, in characters, of buffer */ szFullPath, /* address of buffer for found filename */ &ptr /* address of pointer to file component */ ) == 0) #else hfile = OpenFile(UNZ_DLL_NAME, &ofs, OF_SEARCH); if (hfile == HFILE_ERROR) #endif { char str[256]; wsprintf (str, DLL_WARNING, UNZ_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } #ifndef WIN32 else lstrcpy(szFullPath, ofs.szPathName); _lclose(hfile); #endif /* Now we'll check the unzip dll version information. Note that this is not the same information as is returned from a call to UzpVersion() */ dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd); if (dwVerInfoSize) { BOOL fRet, fRetName; char str[256]; LPSTR lpstrVffInfo; /* Pointer to block to hold info */ LPSTR lszVer = NULL; LPSTR lszVerName = NULL; UINT cchVer = 0; /* Get a block big enough to hold the version information */ hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize); lpstrVffInfo = GlobalLock(hMem); /* Get the version information */ if (GetFileVersionInfo(szFullPath, 0L, dwVerInfoSize, lpstrVffInfo)) { fRet = VerQueryValue(lpstrVffInfo, TEXT("\\StringFileInfo\\040904E4\\FileVersion"), (LPVOID)&lszVer, &cchVer); fRetName = VerQueryValue(lpstrVffInfo, TEXT("\\StringFileInfo\\040904E4\\CompanyName"), (LPVOID)&lszVerName, &cchVer); if (!fRet || !fRetName || (lstrcmpi(lszVer, UNZ_DLL_VERSION) != 0) || (lstrcmpi(lszVerName, COMPANY_NAME) != 0)) { wsprintf (str, DLL_VERSION_WARNING, UNZ_DLL_NAME); printf("%s\n", str); FreeUpMemory(); GlobalUnlock(hMem); GlobalFree(hMem); return 0; } } /* free memory */ GlobalUnlock(hMem); GlobalFree(hMem); } else { char str[256]; wsprintf (str, DLL_VERSION_WARNING, UNZ_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } /* Okay, now we know that the dll exists, and has the proper version * information in it. We can go ahead and load it. */ hUnzipDll = LoadLibrary(UNZ_DLL_NAME); #ifndef WIN32 if (hUnzipDll > HINSTANCE_ERROR) #else if (hUnzipDll != NULL) #endif { Wiz_SingleEntryUnzip = (_DLL_UNZIP)GetProcAddress(hUnzipDll, "Wiz_SingleEntryUnzip"); } else { char str[256]; wsprintf (str, "Could not load %s", UNZ_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } /* Here is where the actual extraction process begins. First we set up the flags to be passed into the dll. */ lpDCL->ncflag = 0; /* Write to stdout if true */ lpDCL->fQuiet = 0; /* We want all messages. 1 = fewer messages, 2 = no messages */ lpDCL->ntflag = 0; /* test zip file if true */ lpDCL->nvflag = 0; /* give a verbose listing if true */ lpDCL->nzflag = 0; /* display a zip file comment if true */ lpDCL->ndflag = 1; /* Recreate directories if true */ lpDCL->naflag = 0; /* Do not convert CR to CRLF */ lpDCL->nfflag = 0; /* Do not freshen existing files only */ lpDCL->noflag = 1; /* Over-write all files if true */ lpDCL->ExtractOnlyNewer = 0; /* Do not extract only newer */ lpDCL->PromptToOverwrite = 0; /* "Overwrite all" selected -> no query mode */ lpDCL->lpszZipFN = argv[1]; /* The archive name */ lpDCL->lpszExtractDir = NULL; /* The directory to extract to. This is set to NULL if you are extracting to the current directory. */ /* As this is a quite short example, intended primarily to show how to load and call in to the dll, the command-line parameters are only parsed in a very simplistic way: We assume that the command-line parameters after the zip archive make up a list of file patterns: " [file_i1] [file_i2] ... [file_iN] [-x file_x1 [file_x2] ...]". We scan for an argument "-x"; all arguments in front are "include file patterns", all arguments after are "exclude file patterns". If no more arguments are given, we extract ALL files. In summary, the example program should be run like: example <archive.name> [files to include] [-x files to exclude] ("<...> denotes mandatory arguments, "[...]" optional arguments) */ x_opt = NULL; if (argc > 2) { infv = &argv[2]; for (infc = 0; infc < argc-2; infc++) if (!strcmp("-x", infv[infc])) { x_opt = infv[infc]; infv[infc] = NULL; break; } exfc = argc - infc - 3; if (exfc > 0) exfv = &argv[infc+3]; else { exfc = 0; exfv = NULL; } } else { infc = exfc = 0; infv = exfv = NULL; } retcode = (*Wiz_SingleEntryUnzip)(infc, infv, exfc, exfv, lpDCL, lpUserFunctions); if (x_opt) { infv[infc] = x_opt; x_opt = NULL; } if (retcode != 0) printf("Error unzipping...\n"); FreeUpMemory(); FreeLibrary(hUnzipDll); return 1; }
// // FUNCTION: About(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for "About" dialog box // This version allows greater flexibility over the contents of the 'About' box, // by pulling out values from the 'Version' resource. // // MESSAGES: // // WM_INITDIALOG - initialize dialog box // WM_COMMAND - Input received // // LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HFONT hfontDlg; // Font for dialog text static HFONT hFinePrint; // Font for 'fine print' in dialog DWORD dwVerInfoSize; // Size of version information block LPSTR lpVersion; // String pointer to 'version' text DWORD dwVerHnd=0; // An 'ignored' parameter, always '0' UINT uVersionLen; BOOL bRetCode; int i; char szFullPath[256]; char szResult[256]; char szGetName[256]; DWORD dwVersion; char szVersion[40]; DWORD dwResult; switch (message) { case WM_INITDIALOG: ShowWindow (hDlg, SW_HIDE); if (PRIMARYLANGID(GetUserDefaultLangID()) == LANG_JAPANESE) { hfontDlg = CreateFont(14, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, 0, 0, 0, VARIABLE_PITCH | FF_DONTCARE, ""); hFinePrint = CreateFont(11, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, 0, 0, 0, VARIABLE_PITCH | FF_DONTCARE, ""); } else { hfontDlg = CreateFont(14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, VARIABLE_PITCH | FF_SWISS, ""); hFinePrint = CreateFont(11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, VARIABLE_PITCH | FF_SWISS, ""); } CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); GetModuleFileName (hInst, szFullPath, sizeof(szFullPath)); // Now lets dive in and pull out the version information: dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd); if (dwVerInfoSize) { LPSTR lpstrVffInfo; HANDLE hMem; hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize); lpstrVffInfo = GlobalLock(hMem); GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpstrVffInfo); // The below 'hex' value looks a little confusing, but // essentially what it is, is the hexidecimal representation // of a couple different values that represent the language // and character set that we are wanting string values for. // 040904E4 is a very common one, because it means: // US English, Windows MultiLingual characterset // Or to pull it all apart: // 04------ = SUBLANG_ENGLISH_USA // --09---- = LANG_ENGLISH // --11---- = LANG_JAPANESE // ----04E4 = 1252 = Codepage for Windows:Multilingual _snprintf_s(szGetName, 256, _TRUNCATE, "%sProductName", GetStringRes(IDS_VER_INFO_LANG)); // Set the title of the dialog: bRetCode = VerQueryValue((LPVOID)lpstrVffInfo, (LPSTR)szGetName, (LPVOID)&lpVersion, (UINT *)&uVersionLen); // Notice order of version and string... if (PRIMARYLANGID(GetUserDefaultLangID()) == LANG_JAPANESE) { _snprintf_s(szResult, 256, _TRUNCATE, "%s のバージョン情報", lpVersion); } else { _snprintf_s(szResult, 256, _TRUNCATE, "About %s", lpVersion); } // ----------------------------------------------------- SetWindowText (hDlg, szResult); // Walk through the dialog items that we want to replace: for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++) { GetDlgItemText(hDlg, i, szResult, sizeof(szResult)); _snprintf_s(szGetName, 256, _TRUNCATE, "%s%s", GetStringRes(IDS_VER_INFO_LANG), szResult); uVersionLen = 0; lpVersion = NULL; bRetCode = VerQueryValue((LPVOID)lpstrVffInfo, (LPSTR)szGetName, (LPVOID)&lpVersion, (UINT *)&uVersionLen); if ( bRetCode && uVersionLen && lpVersion) { // Replace dialog item text with version info strncpy_s(szResult, 256, lpVersion, _TRUNCATE); SetDlgItemText(hDlg, i, szResult); } else { dwResult = GetLastError(); _snprintf_s(szResult, 256, _TRUNCATE, GetStringRes(IDS_VERSION_ERROR), dwResult); SetDlgItemText (hDlg, i, szResult); } SendMessage (GetDlgItem (hDlg, i), WM_SETFONT, (UINT_PTR)((i==DLG_VERLAST)?hFinePrint:hfontDlg), TRUE); } // for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++) GlobalUnlock(hMem); GlobalFree(hMem); } else { // No version information available. } // if (dwVerInfoSize) SendMessage (GetDlgItem (hDlg, IDC_LABEL), WM_SETFONT, (WPARAM)hfontDlg,(LPARAM)TRUE); // We are using GetVersion rather then GetVersionEx // because earlier versions of Windows NT and Win32s // didn't include GetVersionEx: dwVersion = GetVersion(); if (dwVersion < 0x80000000) { // Windows NT _snprintf_s(szVersion, 40, _TRUNCATE, "Microsoft Windows NT %u.%u (Build: %u)", (DWORD)(LOBYTE(LOWORD(dwVersion))), (DWORD)(HIBYTE(LOWORD(dwVersion))), (DWORD)(HIWORD(dwVersion)) ); } else if (LOBYTE(LOWORD(dwVersion))<4) { // Win32s _snprintf_s(szVersion, 40, _TRUNCATE, "Microsoft Win32s %u.%u (Build: %u)", (DWORD)(LOBYTE(LOWORD(dwVersion))), (DWORD)(HIBYTE(LOWORD(dwVersion))), (DWORD)(HIWORD(dwVersion) & ~0x8000) ); } else { // Windows 95 _snprintf_s(szVersion, 40, _TRUNCATE, "Microsoft Windows 95 %u.%u", (DWORD)(LOBYTE(LOWORD(dwVersion))), (DWORD)(HIBYTE(LOWORD(dwVersion))) ); } SetWindowText (GetDlgItem(hDlg, IDC_OSVERSION), szVersion); ShowWindow (hDlg, SW_SHOW); return (TRUE); case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, TRUE); DeleteObject (hfontDlg); DeleteObject (hFinePrint); return (TRUE); } break; } return FALSE; }
LIBUTILS_API char * UTILS_API get_file_versionA(const char * szFile, LARGE_INTEGER * liVersion) { char * pVersion=0; DWORD dwVersionSize, dwHnd; LARGE_INTEGER _liVersion; WORD * s; VS_FIXEDFILEINFO * pBlock; UINT dwBytes; if(!liVersion){ liVersion=&_liVersion; } memset(liVersion,0,sizeof(LARGE_INTEGER)); while(TRUE){ dwHnd = 0; dwVersionSize=GetFileVersionInfoSize((char *)szFile, &dwHnd); if(!dwVersionSize){ return g_szVersion; } pVersion=(char *)malloc(dwVersionSize*4); // *4: for some bugs if(!pVersion){ break; } my_heapchk(); if( !GetFileVersionInfo((char*)szFile, dwHnd, dwVersionSize, pVersion) ){ break; }; my_heapchk(); // Structure used to store enumerated languages and code pages. pBlock=0; dwBytes = sizeof(pBlock); // Retrieve file description for language and code page "i". VerQueryValue(pVersion,"\\",(void**)&pBlock,&dwBytes); my_heapchk(); if(pBlock){ #if 1 liVersion->HighPart=pBlock->dwFileVersionMS; liVersion->LowPart=pBlock->dwFileVersionLS; #else liVersion->HighPart=pBlock->dwProductVersionMS; liVersion->LowPart=pBlock->dwProductVersionLS; #endif } break; }; #ifdef __profile__ time_mark(&t2); utils_debug("get_file_version costs %.3f ms.\n", time_diff(&t2,&t1)*1000); #endif s = (WORD*)liVersion; sprintf(g_szVersion, "%d.%d.%d.%d",s[3],s[2],s[1],s[0]); my_heapchk(); if(pVersion){ free(pVersion); } return g_szVersion; }
LIBUTILS_API char * UTILS_API get_file_descriptionA(const char * szFile, char * szDescription, int len) { char * pVersion=0; DWORD dwVersionSize; struct LANGANDCODEPAGE { WORD wLanguage; WORD wCodePage; } *lpTranslate; char SubBlock[64]; void * lpBuffer; UINT dwBytes; UINT cbTranslate; UINT i; *szDescription=0; dwVersionSize=GetFileVersionInfoSize((char *)szFile,0); if(!dwVersionSize){ return szDescription; } pVersion=(char *)malloc(dwVersionSize); if(!pVersion){ return ""; } if( !GetFileVersionInfo((char*)szFile,0,dwVersionSize,pVersion) ){ free(pVersion); return ""; }; // Read the list of languages and code pages. VerQueryValue(pVersion, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate); if(!cbTranslate){ free(pVersion); return ""; } // Structure used to store enumerated languages and code pages. lpBuffer=0; for(i=0; i < (cbTranslate/sizeof(struct LANGANDCODEPAGE)); i++ ){ wsprintf( SubBlock, TEXT("\\StringFileInfo\\%04x%04x\\FileDescription"), lpTranslate[i].wLanguage, lpTranslate[i].wCodePage); if(0x0804 == lpTranslate[i].wLanguage){ // Retrieve file description for language and code page "i". VerQueryValue(pVersion, SubBlock, &lpBuffer, &dwBytes ); strncpy(szDescription,(char*)lpBuffer,len); szDescription[len-1]=0; free(pVersion); return szDescription; } }; wsprintf( SubBlock, TEXT("\\StringFileInfo\\%04x%04x\\FileDescription"), lpTranslate[0].wLanguage, lpTranslate[0].wCodePage); // Retrieve file description for language and code page "i". VerQueryValue(pVersion, SubBlock, &lpBuffer, &dwBytes ); if(lpBuffer) { strncpy(szDescription,(char*)lpBuffer,len); szDescription[len-1]=0; }; free(pVersion); return szDescription; }
DWORD CreateInstallInfo(_In_ HANDLE hHeap, _Out_ PINSTALLERINFO pInstallerInfo, _Outptr_result_maybenull_ LPVOID *plpData) { TCHAR szModuleFileName[MAX_PATH + 1]; LPTSTR lpszSubBlock, lpszValue; LPWORD lpwLanguage; DWORD dwLen, dwHandle; size_t cbSubBlock; HMODULE hModule; UINT cbSize; HRESULT hr; BOOL res; if (!pInstallerInfo || !plpData) return ERROR_INVALID_PARAMETER; ZeroMemory(pInstallerInfo, sizeof(INSTALLERINFO)); *plpData = NULL; hModule = GetModuleInstance(); if (!hModule) return ERROR_OUTOFMEMORY; dwLen = GetModuleFileName(hModule, szModuleFileName, MAX_PATH); if (!dwLen) return GetLastError(); dwLen = GetFileVersionInfoSize(szModuleFileName, &dwHandle); if (!dwLen) return GetLastError(); *plpData = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, dwLen); if (!*plpData) return ERROR_OUTOFMEMORY; LoadString(hModule, IDS_APPLICATION_ID, (LPWSTR) &pInstallerInfo->pApplicationId, 0); res = GetFileVersionInfo(szModuleFileName, dwHandle, dwLen, *plpData); if (res) { res = VerQueryValue(*plpData, TEXT("\\VarFileInfo\\Translation"), (LPVOID*) &lpwLanguage, &cbSize); if (res) { Trace(TEXT("Translation: %04x%04x (%d)"), lpwLanguage[0], lpwLanguage[1], cbSize); hr = StringCbAPrintf(hHeap, &lpszSubBlock, &cbSubBlock, TEXT("\\StringFileInfo\\%04x%04x\\ProductName"), lpwLanguage[0], lpwLanguage[1]); if (SUCCEEDED(hr)) { Trace(TEXT("SubBlock: %s (%d)"), lpszSubBlock, cbSubBlock); res = VerQueryValue(*plpData, lpszSubBlock, (LPVOID*) &lpszValue, &cbSize); if (res) { pInstallerInfo->pDisplayName = lpszValue; pInstallerInfo->pProductName = lpszValue; } else Trace(TEXT("VerQueryValue 2 failed: %08X"), GetLastError()); HeapSafeFree(hHeap, 0, lpszSubBlock); } else Trace(TEXT("StringCbAPrintf 1 failed: %08X"), hr); hr = StringCbAPrintf(hHeap, &lpszSubBlock, &cbSubBlock, TEXT("\\StringFileInfo\\%04x%04x\\CompanyName"), lpwLanguage[0], lpwLanguage[1]); if (SUCCEEDED(hr)) { Trace(TEXT("SubBlock: %s (%d)"), lpszSubBlock, cbSubBlock); res = VerQueryValue(*plpData, lpszSubBlock, (LPVOID*) &lpszValue, &cbSize); if (res) { pInstallerInfo->pMfgName = lpszValue; } else Trace(TEXT("VerQueryValue 3 failed: %08X"), GetLastError()); HeapSafeFree(hHeap, 0, lpszSubBlock); } else Trace(TEXT("StringCbAPrintf 2 failed: %08X"), hr); } else Trace(TEXT("VerQueryValue 1 failed: %08X"), GetLastError()); } else Trace(TEXT("GetFileVersionInfo failed: %08X"), GetLastError()); Trace(TEXT("ApplicationID: %s"), pInstallerInfo->pApplicationId); Trace(TEXT("DisplayName: %s"), pInstallerInfo->pDisplayName); Trace(TEXT("ProductName: %s"), pInstallerInfo->pProductName); Trace(TEXT("MfgName: %s"), pInstallerInfo->pMfgName); return ERROR_SUCCESS; }