home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / win / prg / cenviw / profile.lib < prev    next >
Text File  |  1994-09-28  |  5KB  |  121 lines

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