home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / CENVIW9.ZIP / PROFILE.LIB < prev    next >
Text File  |  1994-03-08  |  5KB  |  119 lines

  1. // Profile.lib - Cmm routines to interface with Windows' Profile
  2. // ver.1         (i.e. *.INI) files.
  3. //
  4. //
  5. //
  6. //**** GetProfileString(): return key value from .ini file
  7. // SYNTAX: string GetProfileString(string AppName,string KeyName,
  8. //                                 string Default[,string FileName])
  9. // WHERE: AppName: Application name ([AppName] in .ini files)
  10. //        KeyName: Key name under [AppName] in the .ini file
  11. //        Default: Value returned if Key not found; if NULL then returns ""
  12. //        FileName: name of profile file, defaults to WIN.INI if not supplied
  13. // RETURN: Return the profile string if found, else return Default if not found
  14. //
  15. //
  16. //**** WriteProfileString(): write key value to .ini file
  17. // SYNTAX: bool WriteProfileString(string AppName,string KeyName,
  18. //                                 string Value[,string FileName])
  19. // WHERE: AppName: Application name ([AppName] in .ini files)
  20. //        KeyName: Key name under [AppName] in the .ini file
  21. //        Value: String to set KeyName equal to in the .INI file
  22. //        FileName: name of profile file, defaults to WIN.INI if not supplied
  23. // RETURN: Return FALSE if failure, else success
  24. //
  25. //
  26. //**** GetProfileInt(): return key value from .ini file as an integer
  27. // SYNTAX: int GetProfileInt(string AppName,string KeyName,
  28. //                           int Default[,string FileName])
  29. // WHERE: AppName: Application name ([AppName] in .ini files)
  30. //        KeyName: Key name under [AppName] in the .ini file
  31. //        Default: Value returned if Key not found
  32. //        FileName: name of profile file, defaults to WIN.INI if not supplied
  33. // RETURN: Return the profile integer if found, else return Default if not found
  34. //
  35. //
  36. //**** WriteProfileInt(): write key value to .ini file
  37. // SYNTAX: bool WriteProfileInt(string AppName,string KeyName,
  38. //                              int Value[,string FileName])
  39. // WHERE: AppName: Application name ([AppName] in .ini files)
  40. //        KeyName: Key name under [AppName] in the .ini file
  41. //        Value: Integer value to set KeyName equal to in the .INI file
  42. //        FileName: name of profile file, defaults to WIN.INI if not supplied
  43. // RETURN: Return FALSE if failure, else success
  44. //
  45. //
  46. //**** GetProfileKeyList(): Get array of all keys in a profile file
  47. // SYNTAX: string[] GetProfileKeyList(string AppName[,string FileName])
  48. // WHERE: AppName: Application name ([AppName] in .ini files)
  49. //        FileName: name of profile file, defaults to WIN.INI if not supplied
  50. // RETURN: Returns array of all keys under AppName; NULL if none found
  51. //
  52. //
  53.  
  54.  
  55. GetProfileString(pAppName,pKeyName,pDefault,pFileName)
  56. {
  57.    lRetString[0] = lRetString[500] = '\0';
  58.    lDefault = pDefault ? pDefault : "" ;
  59.    lRetLength = ( 3 < va_arg() ) 
  60.               ? DynamicLink("KERNEL","GETPRIVATEPROFILESTRING",SWORD16,PASCAL,
  61.                             pAppName,pKeyName,lDefault,lRetString,499,pFileName)
  62.               : DynamicLink("KERNEL","GETPROFILESTRING",SWORD16,PASCAL,
  63.                             pAppName,pKeyName,lDefault,lRetString,499) ;
  64.    lRetString[lRetLength] = 0;
  65.    return lRetString;
  66. }
  67.  
  68. WriteProfileString(pAppName,pKeyName,pValue,pFileName)
  69. {
  70.    return ( 3 < va_arg() )
  71.         ? DynamicLink("KERNEL","WRITEPRIVATEPROFILESTRING",SWORD16,PASCAL,
  72.                       pAppName,pKeyName,pValue,pFileName)
  73.         : DynamicLink("KERNEL","WRITEROFILESTRING",SWORD16,PASCAL,
  74.                       pAppName,pKeyName,pValue) ;
  75. }
  76.  
  77. GetProfileInt(pAppName,pKeyName,pDefault,pFileName)
  78. {
  79.    return ( 3 < va_arg() )
  80.         ? DynamicLink("KERNEL","GETPRIVATEPROFILEINT",UWORD16,PASCAL,
  81.                       pAppName,pKeyName,pDefault,pFileName)
  82.         : DynamicLink("KERNEL","GETPROFILEINT",UWORD16,PASCAL,
  83.                       pAppName,pKeyName,pDefault) ;
  84. }
  85.  
  86. WriteProfileInt(pAppName,pKeyName,pValue,pFileName)
  87. {
  88.    sprintf(lValue,"%u",pValue);
  89.    return ( 3 < va_arg() )
  90.         ? WriteProfileString(pAppName,pKeyName,lValue,pFileName)
  91.         : WriteProfileString(pAppName,pKeyName,lValue) ;
  92. }
  93.  
  94. GetProfileKeyList(pAppName,pFileName)
  95. {
  96.    // get buffer big enough to receive all strings
  97.    lReceiveLen = 0;
  98.    do {
  99.       lReceiveLen += 500;
  100.       lRetString[0] = lRetString[lReceiveLen+1] = '\0';
  101.       lRetLength = ( 1 < va_arg() )
  102.                  ? DynamicLink("KERNEL","GETPRIVATEPROFILESTRING",SWORD16,PASCAL,
  103.                                pAppName,0,0,"",lRetString,lReceiveLen,pFileName)
  104.                  : DynamicLink("KERNEL","GETPROFILESTRING",SWORD16,PASCAL,
  105.                                pAppName,0,0,"",lRetString,lReceiveLen) ;
  106.    } while ( lReceiveLen < (lRetLength + 10) );
  107.  
  108.    lKeyCount = 0;
  109.    while ( 0 < lRetLength ) {
  110.       if ( 1 < (lUsedLength = 1 + strlen(lRetString)) )
  111.          strcpy(lKeyList[lKeyCount++],lRetString);
  112.       lRetString += lUsedLength;
  113.       lRetLength -= lUsedLength;
  114.    }
  115.  
  116.    return ( lKeyCount ) ? lKeylist : NULL ;
  117. }
  118.  
  119.