2

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.

David G
  • 94,763
  • 41
  • 167
  • 253
user1386966
  • 3,302
  • 13
  • 43
  • 72
  • Trying to reverse ? can you explain more ?! – Amir Naghizadeh Nov 25 '12 at 09:36
  • 3
    FindResource, LoadResource, SizeofResource, LockResource, UnlockResource FreeResource. And about a million web-hits on ["WIN32 DLL Resource Loading"](https://www.google.com/search?client=safari&rls=en&q=WIN32+DLL+Resource+Loading&ie=UTF-8&oe=UTF-8) – WhozCraig Nov 25 '12 at 09:45
  • yes sure, when I right-clicked the project in VS2010 I've added : add->resource->Version. and then I got the window with CompanyName, Version , ProductName and more... I want to write a function that for exampe can give me the company name .. but I can't understand how I can enter the resource file and get it.. I think there is a winapi for it..but I just can't find it – user1386966 Nov 25 '12 at 09:46
  • You want to read the version resource rather than general resources right? – David Heffernan Nov 25 '12 at 10:11
  • yes..I just cant understand how to do it – user1386966 Nov 25 '12 at 10:26
  • If you need an example of cracking open info from a VERSIONINFO, perhaps [this answer](http://stackoverflow.com/questions/316626/how-do-i-read-from-a-version-resource-in-visual-c/2326124) may assist. – WhozCraig Nov 25 '12 at 11:48

1 Answers1

1

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;
}

`

Edward Clements
  • 5,040
  • 2
  • 21
  • 27
  • thanks , what should I put inside :lpszVersionString? and the first parameter is the path of the DLL> – user1386966 Nov 25 '12 at 15:18
  • lpszVersionString is the output parameter for example char szCompanyName[_MAX_PATH]; GetVersionString(lpszModuleFileName, TEXT("CompanyName"), szCompanyName); – Edward Clements Nov 25 '12 at 16:36
  • I always get : error LNK2019Lunresolved external symbol _GetFileVersionInfo@16 referenced in function "struct_ver* _cdecl..." what does it mean? Am I doing something wrong? – user1386966 Nov 25 '12 at 18:04
  • 1
    did you include the "#pragma comment(lib, "version.lib")" line in your source? otherwise, you would need to include version.lib in your Linker-Input-AdditionalDependencies option in your project properties – Edward Clements Nov 25 '12 at 22:03