How To: Getting strings from the resx file of your form

Recently I wanted a place to save strings in my MFC app using the string storage that .NET provides in resx, rather than use the ancient rc file included in the legacy app I'm working on. The code below shows you how:

// create the resource manager from the name

// of the resx file (don't forget to include the namespace)

Resources::ResourceManager^ rm = gcnew Resources::ResourceManager("ClientsProject.ScrollableMessageBox", System::Reflection::Assembly::GetExecutingAssembly());

//  Get the string value from the resx file using the key of the string

String^ helpExtension = (String^ )rm->GetString("HelpExtension");

 

Note: If you are not sure of the namespace of your resource, use the following trick.  Open the compiled assembly in reflector and look at the resource section of your assembly.  You'll see the name in the tree tab in reflector.