views:

33

answers:

1

I'm reading an entry from the registry that comes out something like:

@%SystemRoot%\\System32\\wscsvc.dll,-200

I need to actually load the string from the file.

I found an article which describes how the number on the end behaves (negative == specific resource ID, positive == the nth resource in the file), but I'm confused as to how one might load the resource. The ExtractIcon function seems to do the resource loading I need, but it returns an HICON, not a string.

How might I load the string from the file?

+2  A: 

Load the DLL with LoadLibrary, load the string with LoadString, and then unload the DLL (assuming you don't need anything else from it) with FreeLibrary:

HMODULE hDll = LoadLibrary("C:\\WINDOWS\\System32\\wscsvc.dll");
if(hDll != NULL)
{
    wchar_t *str;
    if(LoadStringW(hDll, +200, (LPWSTR)&str, 0) > 0)
        ;  // success!  str now contains a (read-only) pointer to the desired string
    else
        ;  // handle error
    FreeLibrary(hDll);
}
else
    ;  // handle error

Note that LoadLibrary (and pretty much any other function that takes in a filename) does not understand environment variables like %SystemRoot%. You'll have to use a function such as ExpandEnvironmentStrings to expand the environment variables in the DLL filename before passing it to LoadLibrary.

Adam Rosenfield
Woah.. do I feel dumb. Thanks :)
Billy ONeal