title: How do I get a string resource by name in win32 or MFC?
body: <p>I'd like to query if a string is in the string table prior to getting it as some of the items may not be  in the string table.  <strong>To make this clear, the symbol may or may not have been declared</strong>, so I cannot just specify the string id because it may or may not exist and will cause a compile error if it doesn't.</p>
  
  <p>From a console application base, I tried this:</p>
  
  <h1>ConsoleApplication4.rc:</h1>
  
  <pre><code>STRINGTABLE
  BEGIN
     IDS_APP_TITLE       "ConsoleApplication4"
     IDS_TEST_Home_HERE  "Home here"
  END
  </code></pre>
  
  <h1>Resource.h</h1>
  
  <pre><code>//{{NO_DEPENDENCIES}}
  // Microsoft Visual C++ generated include file.
  // Used by ConsoleApplication4.rc
  //
  
  #define IDS_APP_TITLE           103
  #define IDS_TEST_Home_HERE      104
  // Next default values for new objects
  //
  #ifdef APSTUDIO_INVOKED
  #ifndef APSTUDIO_READONLY_SYMBOLS
  #define _APS_NEXT_RESOURCE_VALUE    101
  #define _APS_NEXT_COMMAND_VALUE     40001
  #define _APS_NEXT_CONTROL_VALUE     1000
  #define _APS_NEXT_SYMED_VALUE       101
  #endif
  #endif
  </code></pre>
  
  <h1>ConsoleApplication4.cpp:</h1>
  
  <pre><code>int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  {
      int nRetCode = 0;
  
      HMODULE hModule = ::GetModuleHandle(NULL);
  
      if (hModule != NULL)
      {
          // initialize MFC and print and error on failure
          if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
          {
              // TODO: change error code to suit your needs
              _tprintf(_T("Fatal Error: MFC initialization failed\n"));
              nRetCode = 1;
          }
          else
          {
              // TODO: code your application's behavior here.
          }
      }
      else
      {
          // TODO: change error code to suit your needs
          _tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
          nRetCode = 1;
      }
  
      // vvvv My code below here vvvv:
  
      HRSRC hResource = FindResource(hModule, _T("IDS_TEST_Home_HERE"), RT_STRING);
      HGLOBAL hgString = LoadResource(hModule, hResource);
      LPCTSTR string = (LPCTSTR)LockResource(hgString);
  
      cout &lt;&lt; string &lt;&lt; endl;
  
      // ^^^^ My code above here ^^^^
  
      return nRetCode;
  }
  </code></pre>
  
  <p>However, the <code>FindResource()</code> call returns <code>NULL</code>.  What am I missing?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>For anyone interested, I wrote a way to read in id symbol names from a file and convert them to the symbol's numerical value so long as the read in symbol is somehow based on the the original symbol id that is being queried about.</p>
  
  <p>Doing this would allow me to query about an additional symbol's string resource value, which can be picked from a list of predetermined choices.</p>
  
  <p>You can see the solution <a href="https://stackoverflow.com/a/28100406/1366368">below</a>.</p>