Reputation: 1227
Can anyone help me to load values in a STRINGTABLE in vc++ programmatically? I'm using the MFC.
Upvotes: 2
Views: 3566
Reputation: 4072
You can load strings directly from a string table using the LoadString method, I use it all the time.
http://msdn.microsoft.com/en-us/library/ms647486(v=vs.85).aspx
CStringW myString;
myString.LoadString(RESOURCE_ID); //where RESOURCE_ID is the Stringtable
//entry ID
*EDIT: Thanks for the input this makes the answer much better!!
Upvotes: 4
Reputation: 308206
It's hard to know what you're really asking for, but I'm going to try an answer. This assumes you're asking how to put the strings into resources, rather than how to read an existing resource.
The .rc
file containing the resources can contain #include
directives. All you have to do is write out a text file containing the strings you want to include, along with the STRINGTABLE, BEGIN, and END directives along with the ID of each string. You should also create a .h
file that defines each of the IDs and include that in the .rc
too.
Upvotes: 0
Reputation: 18431
You can have a custom resource where you would put a text file. At runtime, read that text file as resource.
void GetResourceAsString(int nResourceID, CStringA &strResourceString)
{
HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(nResourceID), L"DATA");
HGLOBAL hResHandle = LoadResource(NULL, hResource);
// Resource is ANSII
const char* lpData = static_cast<char*> ( LockResource(hResHandle) );
strResourceString.SetString(lpData, SizeofResource(NULL, hResource));
FreeResource(hResource);
}
Where DATA
would be your custom resource type, and nResource
would be resource-id under DATA
resource type. Of course, you can choose another other name rather than "DATA".
Upvotes: 2
Reputation: 23550
Normally you define for each string a constant that gets included in your program as well as in the resource-file. The string resource is then placed in the .rsrc-section of your executable and strings can be retrieved with LoadString() by naming the defined constant for that string.
Maybe you instead want to iterate through all the string-resources of your executable at run-time? You can do that by reading your process-memory at the appropriate entry in the PE-struct. You can find the string-table entry in the PE-struct if you tahttp://msdn.microsoft.com/en-us/windows/hardware/gg463119.aspx under "Resource Directory Table" or have a look into the winapi include-files which define the PE-structs.
Upvotes: 0