Click here to Skip to main content
15,559,819 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I know it's a little bit tricky but I need it for an application.
Generally we use LoadString function to load a string from a resource in language, specifying the HINSTANCE of the dll.

What I have tried:

I'm looking for a way to reverse this method by knowing the string and the HINSTANCE where to look in to retrieve the ID.
Posted
Updated 29-Jun-16 4:02am

If you need to do this by code just iterate over the possible IDs.

Untested example based on existing code to scan string resources in DLLs:
C++
int GetID(HMODULE hModule, LPCTSTR str)
{
    // Declare CString object outside the loop to avoid 
    //  memory allocation with each call to LoadString().
    CString strItem;
    for (unsigned long i = 0; i <= 0xFFFF; i++)
    {
        if (strItem.LoadString(hModule, i))
        {
            if (strItem == str)
                return i;
        }
    }
    return -1;
}

If the DLL is not already loaded, load it as data file using LoadLibraryEx with parameters DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE.
 
Share this answer
 
Comments
nv3 29-Jun-16 11:27am    
My 5. And I guess there is even a way to avoid iterating over all 2**16 possible IDs. But that requires looking a little deeper into the exe file format.
Jochen Arndt 29-Jun-16 11:35am    
Thank you.
When knowing the format it should be possible to locate the existing IDs and compare the retrieved strings (or get them while parsing for the IDs).

But iterating over all possible IDs should be fast enough. If have executed my existing code which tries all IDs and appends the strings to an edit control with the wininet.dll (2 MB):
It took less than a second.
It is an easy trick: open the dll in Visual Studio as resource file. ("Open File" + select "resource" as file type)

Than you see the string list table and can search for it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900