Home Search Contact us About us
Title Building a text file into the Executable
Summary How to make a text file available at run time and compiled directly into the executable. This is useful for such things as copyright notices.
Contributor John McTainsh
Published 8-Sep-2000
Last updated 8-Sep-2000
Page rating   83% for 12 votes Useless Brilliant

Description.

Using LoadString() is convenient but does not suit large documents which can more easily be edited in notepad type editors and kept in separate files to enable better source control.

Solution.

  • Put the Text file in the project\res directory.
  • Add the Text file to VSS.
  • Add the following line to MyApplication.rc2 (In this example the text file is called JohnsNotes.txt.
    IDTXT_JOHNS_NOTES TEXT res\JohnsNotes.txt
  • Where the text is to be loaded place the following code. Note in this example the text is placed into an exit box called IDC_NOTES.
    //Insert the Licence agreement  
    HINSTANCE hAppRes = AfxGetResourceHandle(); 
    HRSRC hResTemp = ::FindResource( hAppRes, "IDTXT_JOHNS_NOTES", "TEXT" ); 
    HANDLE hTextResource = ::LoadResource( hAppRes, hResTemp ); 
    if( hTextResource ) 
    { 
        //Points to  ocked data in memory
        LPSTR lpResData = (LPSTR)::LockResource( hTextResource ); 
        SetDlgItemText( IDC_THE_NOTES, lpResData ); 
        ::FreeResource( hTextResource ); 
    }  
Comments Date
Home Search Contact us About us