2

Can anyone provide an explanation or a link that explains how exactly a STRINGTABLE in a MFC resource file is defined and can be manually expanded?

I tried to do it, but failed to do so in a multi project solution. Most projects in said solution have their own resource files and renamed resource.h-files.

When the application tries to access the string resources, the error message 'Resource string for '22392' not found' shows up. 22392 is the ID of the string I tried to create. I don't get a similar error message if I use an already defined string ID instead.

Using the Visual Studio 2010's wizard to add a string resource didn't work either. But it shows up correctly in the listing of resource symbols and in the string table editor.

Needless to say that I haven't participated in the creation of this solution.

Thanks for your help.

[EDIT1]

I excluded the possibility of conflict by performing a ‘find in files’ for the value used and using other values as well: 22390, 22391, 22393, 22394, 22395. Always got the same result.

[EDIT2]

I repeated the steps I did in the complex solution in a new, clean and simple MFC application with one project and it worked without problems. Therefore I assume my problem is related to the fact that the solution has multiple projects and resources.

The steps were the following:

  1. Pick a free number in the resource.h (which is named differently in my case) and add a #define IDS_XXX free number.
  2. Validate the chosen number by performing a ‘find in files’ with it.
  3. Add a line to a STRINGTABLE in resource.h, preferably close to a IDS_ with a value close to the one I picked.

    STRINGTABLE
    BEGIN
      IDS_OTHER          "I have a number close to XXX"
      IDS_XXX            "HelloHello"
    END
    
  4. Access the string in the application:

    CString strMyString;
    strMyString.LoadString(IDS_XXX); 
    AfxMessageBox(strMyString, MB_YESNO | MB_ICONEXCLAMATION);
    

[EDIT3]

I tried to locate the call of LoadString that causes the error message. The LoadString that fails to load my string resource is located in a class, that is in the same project as the resource file (.rc) containing said string resource. The error message 'Resource string for '22392' not found' is generated there. That explains at least why I found nothing googeling it.

[EDIT4]

I could isolate the cause further.

In cstringt.h hInst is NULL aka the string ressource can't be found:

_Check_return_ BOOL LoadString(_In_ UINT nID)
{
    HINSTANCE hInst = StringTraits::FindStringResourceInstance( nID );
    if( hInst == NULL )
    {
        return( FALSE ); // goes here, but shouldn't, hInst == NULL
    }
    return( LoadString( hInst, nID ) );
}

This is strange since it is possible to access another string ressource within the same resource file just fine.

red_rain
  • 398
  • 4
  • 15
  • There are options to start the numbering of resources, and I used them some time ago to handle a set of MFC Extensions DLLs. I think these were in options/resources... I'm sorry I don't have now MSVC with MFC available... – CapelliC Mar 09 '12 at 11:32
  • @chac: If you are suggesting to change the existing numbering of the resources, that is out of question, since the solution has been under development for more than a decade and all hell would break loose if I tried something like that. – red_rain Mar 09 '12 at 11:40

2 Answers2

1

The "Resource string for '22392' not found" error sounds like Windows cannot find that specific string in the string table although this conflicts with your statement "but it shows up correctly in the listing of resource symbols and in the string table editor". A few things I would do or check to narrow down the issue:

  • Clean/rebuild the entire project and or solution. I've seen too much strange behaviour from VS just due to bad or out of date builds that this is usually the first thing I try.
  • Edit the RC file in a text editor: right-click on the RC file and "View Code" in VS2010. Confirm that string 22392 is actually present and valid. Check the entries before and after it as well.
  • Delete the string from the string table and resource.h. Re-create the string from the resource editor.
  • You mention "renamed resource.h files". I'm not entirely sure what you mean but make sure these are used properly in the RC file: they should be included at the top when looking at it in a text editor.
  • Make sure the defined name for 22392 is not redefined somewhere else in the project.

If the string is present in the string table and you still get the "not found" error then something else is going on.

uesp
  • 6,194
  • 20
  • 15
  • The rebuild, which took an hour, did the trick. Thanks, you saved me a lot of trouble. – red_rain Mar 09 '12 at 14:29
  • 2
    Glad it worked. I've never had issues in previous versions but VS2010 regularly messes up builds and doesn't properly detect which files to rebuild after a file change. I don't know exactly how or why this happens but my first step now when I see "weird" bugs occur is a complete rebuild. This sucks for large projects but I'd rather spend an hour letting the computer rebuild than an hour trying to track a bug that doesn't exist. – uesp Mar 09 '12 at 15:38
0

The definitions for the ID's are present in Resource.h. Probably someone might have added a string and deleted the entry in Resource.h thats why it is showing you the error message. Open the resource.h and add #define IDS_XXX 22392

Jeeva
  • 4,585
  • 2
  • 32
  • 56
  • The corresponding Resource.h has another name and that's where I already added my #define IDS_XXX 22392. If I remove this line, the solution won’t compile: undeclared identifier. So the compiler noticed the #define. I guess the program has a problem using my custom ID during runtime, any chance that this is related to the usage of multiple projects and resources in this solution? – red_rain Mar 09 '12 at 10:48
  • @red_rain: It may be because of confilct. can you try it with different value other than 22392 – Jeeva Mar 09 '12 at 10:58
  • I excluded the possibility of conflict by performing a ‘find in files’ for the value used and using other values as well: 22390, 22391, 22393, 22394, 22395. Always got the same result. Please also have a look at my other edit to the question. – red_rain Mar 09 '12 at 11:24