Reputation: 3392
I have a project that is compiling into a DLL , and a resource file that I added manually. I'm looking for Win32 API that can help me find resource files and get information and data from them (using C++).
For example - to get the Company Name or the version..
Can anyone help me with it?
Thanks.
Upvotes: 2
Views: 1420
Reputation: 5132
call the function below passing TEXT("CompanyName") as lpszVersionType `
#pragma comment(lib, "version.lib")
BOOL GetVersionString(LPCTSTR lpszModuleFileName, LPCTSTR lpszVersionType, LPTSTR lpszVersionString)
{ int i, j;
unsigned long u;
LPTSTR pBlock, pTmpVersion;
TCHAR buf[_MAX_PATH];
BOOL bRet = FALSE;
struct LANGANDCODEPAGE
{ WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
if ((i = GetFileVersionInfoSize(lpszModuleFileName, &u)) == 0) // !!
return FALSE;
i++;
pBlock = (LPTSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, i * sizeof(TCHAR));
if (pBlock == NULL) // !!
return FALSE;
if (GetFileVersionInfo(lpszModuleFileName, u, i, pBlock))
{ VerQueryValue(pBlock, TEXT ("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, (UINT *)&u); // // Read the list of languages and code pages
j = (int)(u/sizeof(struct LANGANDCODEPAGE));
for (i = 0; i < j; i++)
{ wsprintf(buf, TEXT ("\\StringFileInfo\\%04x%04x\\%s"), lpTranslate[i].wLanguage, lpTranslate[i].wCodePage, lpszVersionType);
VerQueryValue(pBlock, buf, (void **)&pTmpVersion, (UINT *)&u);
if (u > 0)
{ lstrcpy(lpszVersionString, pTmpVersion);
bRet = TRUE;
break;
}
}
}
HeapFree(GetProcessHeap(), 0, pBlock);
return bRet;
}
`
Upvotes: 1