home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / memsz331.zip / Source.zip / RESTRING.CPP < prev    next >
Text File  |  1996-03-29  |  1KB  |  45 lines

  1. // Class RESTRING: Encapsulates the load/discard
  2. //   logic for a resource String Table entry.
  3.  
  4. #define INCL_BASE
  5. #include <os2.h>
  6.  
  7. #include "debug.h"
  8.  
  9. #include "restring.h"
  10.  
  11. // #define DEBUG
  12.  
  13.  
  14.   // Constructor
  15.  
  16. ResourceString::ResourceString ( HMODULE Module, ULONG Id ) : StringPointer(0) {
  17.  
  18.    SavedModule = Module ;
  19.    SavedId = Id ;
  20.  
  21.    APIRET Status = DosGetResource ( Module, RT_STRING, Id/16+1, &BlockPointer ) ;
  22.    if ( Status ) {
  23.       Log ( "ERROR: Unable to get string resource.  Module %lu, id %lu, code %08lX.",
  24.          SavedModule, SavedId, Status ) ;
  25.       return ;
  26.    } /* endif */
  27.  
  28.    StringPointer = PSZ(BlockPointer) + sizeof(USHORT) ;
  29.  
  30.    USHORT Index = (USHORT) ( Id % 16 ) ;
  31.    while ( Index-- ) {
  32.       #ifdef DEBUG
  33.       Log ( "ResourceString: Searching for ID %08X, skipping string '%s' (len %u).", Id, StringPointer+1, *PUCHAR(StringPointer) ) ;
  34.       #endif
  35.       StringPointer += * PUCHAR ( StringPointer ) ;
  36.       StringPointer ++ ;
  37.    } /* endwhile */
  38.  
  39.    StringPointer ++ ;
  40.  
  41.    #ifdef DEBUG
  42.    Log ( "ResourceString: Searching for ID %08X, found string '%s' (len %u).", Id, StringPointer, *PUCHAR(StringPointer-1) ) ;
  43.    #endif
  44. }
  45.