C++/CLI string tables

I made the move from MFC to C++/CLI about 6 months ago and one thing that really peeves me is the new way resources are handled by Visual Studio 2005. I refuse to directly edit resource files (via the VS resource editor) because it too often messes up the layout of my form or breaks it all together. I've been very bad and placed a lot of string literals in code, until I figure out how I want to handle them.

My question is...for those of you who use C++/CLI Winforms, how do you handle your resources (primary talking strings). Do you use the resX files



Answer this question

C++/CLI string tables

  • skidog

    If you create a new form in your application VS 2005 will create a <FormName>.resx file that contains the resources for this form. The resources in this file will be embedded into your assembly.

    Anytime you modify your form with the designer it might also write into the <FormName>.resx file. So I wouldn't add my own strings there by editing the file.

    Instead I would create a seperate resources file, e.g. containing all the error messages of the application. To do that, right-click on your project in the solution explorer and add a new item of type Assembly Resouce File (.resx). Give it the name ErrorMessages.resx.

    Add your strings there, e.g. a message with the name "Error".

    In your code you can retrieve the string by the lines, assuming that your root namespace name is "VCWinForm".

    Resources::ResourceManager^ rm = gcnew Resources::ResourceManager(L"VCWinForm.ErrorMessages", this->GetType()->Assembly);

    MessageBox::Show(rm->GetString(L"Error"));

    You can later localize your error messages, e.g. in german, by creating another Assembly Resource File with the name ErrorMessages.de.resx.

    Regards, Bernd

     


  • WildRich

    Thanks, that sounds like a good idea. I think I'll give it a try.
  • C++/CLI string tables