home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / mapi / win16 / dev / misc / strtbl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  5.4 KB  |  252 lines

  1. /*
  2.  -  S T R T B L . C
  3.  -  Copyright (C) 1995 Microsoft Corporation
  4.  -
  5.  *  Purpose:
  6.  *      Contains the GetString() function which allows us to
  7.  *      implement named string tables.  This function uses
  8.  *      strings that where pre-processed from the MAPITEST.STR
  9.  *      string table file in this directory.  The pre-processor
  10.  *      used is called SC.EXE and can be found in the \preproc
  11.  *      sub-directory below this one.
  12.  *
  13.  */
  14.  
  15. #include <windows.h>
  16. #include <strtbl.h>
  17. #include <strdef.h>
  18.  
  19.  
  20. /*
  21.  -  GetString
  22.  *
  23.  *  Purpose:
  24.  *      Retrieves a string associated with the ID from the
  25.  *      named string table.
  26.  *
  27.  *  Parameters:
  28.  *      lpszName        - The name of the string table to use
  29.  *      ulID            - The ID of the string you wish to retrieve
  30.  *      lpsz            - Pointer to the buffer to copy the string into
  31.  *
  32.  *  Returns:
  33.  *      lpsz            - The pointer to the destination buffer passed in
  34.  *
  35.  */
  36.  
  37. LPSTR CDECL GetString(LPSTR lpszName, LONG ulID, LPSTR lpsz)
  38. {
  39.     ULONG   idxTbl = 0;
  40.     ULONG   idxStr = 0;
  41.  
  42.     while(idxTbl < NUM_TABLES)
  43.     {
  44.         if(!lstrcmpi(lpszName, st[idxTbl].lpszName))
  45.             break;
  46.  
  47.         idxTbl++;
  48.     }
  49.  
  50.     if(idxTbl == NUM_TABLES)
  51.         return NULL;
  52.  
  53.     while(idxStr < st[idxTbl].cEntrys)
  54.     {
  55.         if(st[idxTbl].lpEntry[idxStr].ulID == ulID)
  56.             break;
  57.  
  58.         idxStr++;
  59.     }
  60.  
  61.     if(idxStr == st[idxTbl].cEntrys)
  62.     {
  63.         if(lpsz)
  64.             wsprintf(lpsz,"0x%08X",ulID);       // id not found, return textized HEX value
  65.         return NULL;                        // to '(null)'; return NULL
  66.     }
  67.  
  68.     if(lpsz)
  69.     {
  70.         lstrcpy(lpsz, st[idxTbl].lpEntry[idxStr].lpszValue);
  71.         return lpsz;
  72.     }
  73.     else
  74.         return(st[idxTbl].lpEntry[idxStr].lpszValue);
  75. }
  76.  
  77.  
  78. /*
  79.  -  GetRowString
  80.  *
  81.  *  Purpose:
  82.  *      Retrieves a string associated with the Row of the Table 
  83.  *
  84.  *  Parameters:
  85.  *      lpszName        - The name of the string table to use
  86.  *      ulRow           - The Row in the table of the string you wish to retrieve
  87.  *      lpsz            - Pointer to the buffer to copy the string into
  88.  *
  89.  *  Returns:
  90.  *      lpsz            - The pointer to the destination buffer passed in
  91.  *
  92.  */
  93.  
  94. LPSTR CDECL GetRowString(LPSTR lpszName, ULONG ulRow, LPSTR lpsz)
  95. {
  96.     ULONG   idxTbl = 0; 
  97.  
  98.     /* find which table we are looking for */
  99.     while(idxTbl < NUM_TABLES)
  100.     {
  101.         if(!lstrcmpi(lpszName, st[idxTbl].lpszName))
  102.             break;
  103.  
  104.         idxTbl++;
  105.     }
  106.  
  107.     if(idxTbl == NUM_TABLES)
  108.         return NULL;
  109.  
  110.     /* check to see the row is in range */
  111.     
  112.     if( ulRow >= st[idxTbl].cEntrys)
  113.     {
  114.         wsprintf(lpsz,"Row %lu Not Found",ulRow);     
  115.         return NULL;                    
  116.     }
  117.  
  118.     lstrcpy(lpsz, st[idxTbl].lpEntry[ulRow].lpszValue);
  119.  
  120.     return lpsz;
  121. }
  122.  
  123.  
  124.  
  125. /*
  126.  -  GetRowID
  127.  *
  128.  *  Purpose:
  129.  *      Retrieves a ID associated with the Row of the Table 
  130.  *
  131.  *  Parameters:
  132.  *      lpszName        - The name of the string table to use
  133.  *      ulRow           - The Row in the table of the string you wish to retrieve
  134.  *
  135.  *  Returns:
  136.  *      ULONG           - ID of row in table
  137.  *
  138.  */
  139.  
  140.  
  141. ULONG CDECL GetRowID(LPSTR lpszName,ULONG ulRow)
  142. {
  143.     ULONG   idxTbl = 0; 
  144.  
  145.     /* find which table we are looking for */
  146.     while(idxTbl < NUM_TABLES)
  147.     {
  148.         if(!lstrcmpi(lpszName, st[idxTbl].lpszName))
  149.             break;
  150.  
  151.         idxTbl++;
  152.     }
  153.  
  154.     if(idxTbl == NUM_TABLES)
  155.         return 0;
  156.  
  157.     /* check to see the row is in range */
  158.     
  159.     if( ulRow >= st[idxTbl].cEntrys)
  160.         return 0;                    
  161.  
  162.     return( st[idxTbl].lpEntry[ulRow].ulID);
  163. }
  164.  
  165. /*
  166.  -  GetRowCount
  167.  *
  168.  *  Purpose:
  169.  *      Retrieves the number of items/rows in the table
  170.  *
  171.  *  Parameters:
  172.  *      lpszName        - The name of the string table to get rowcount of
  173.  *
  174.  *  Returns:
  175.  *      ulCount         - Number of rows in table
  176.  *
  177.  */
  178.  
  179. ULONG CDECL GetRowCount(LPSTR lpszName)
  180. {
  181.     ULONG   idxStr = 0;
  182.     ULONG   idxTbl = 0; 
  183.  
  184.     /* find which table we are looking for */
  185.     while(idxTbl < NUM_TABLES)
  186.     {
  187.         if(!lstrcmpi(lpszName, st[idxTbl].lpszName))
  188.             break;
  189.  
  190.         idxTbl++;
  191.     }
  192.  
  193.     if(idxTbl == NUM_TABLES)
  194.         return 0;
  195.  
  196.     /* check to see the row is in range */
  197.     
  198.     return(st[idxTbl].cEntrys);
  199. }
  200.  
  201.  
  202.  
  203.  
  204. /*
  205.  -  GetID
  206.  *
  207.  *  Purpose:
  208.  *      Retrieves an ID associated with the string from the
  209.  *      named string table.
  210.  *
  211.  *  Parameters:
  212.  *      lpszName        - The name of the string table to use
  213.  *      lpsz            - Pointer to the string to search for
  214.  *      lpulID          - The ID of the string you were searching for
  215.  *
  216.  *  Returns:
  217.  *      fFound          - Boolean indicating if the ID was found
  218.  *
  219.  */
  220.  
  221. BOOL CDECL GetID(LPSTR lpszName, LPSTR lpsz, LONG *lpulID)
  222. {
  223.     ULONG   idxTbl = 0;
  224.     ULONG   idxStr = 0;
  225.  
  226.     while(idxTbl < NUM_TABLES)
  227.     {
  228.         if(!lstrcmpi(lpszName, st[idxTbl].lpszName))
  229.             break;
  230.  
  231.         idxTbl++;
  232.     }
  233.  
  234.     if(idxTbl == NUM_TABLES)
  235.         return FALSE;
  236.  
  237.     while(idxStr < st[idxTbl].cEntrys)
  238.     {
  239.         if(!lstrcmp(st[idxTbl].lpEntry[idxStr].lpszValue, lpsz))
  240.             break;
  241.  
  242.         idxStr++;
  243.     }
  244.  
  245.     if(idxStr == st[idxTbl].cEntrys)
  246.         return FALSE;
  247.  
  248.     *lpulID = st[idxTbl].lpEntry[idxStr].ulID;
  249.  
  250.     return TRUE;
  251. }
  252.