home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / PROFILE.LIB < prev    next >
Text File  |  1994-05-19  |  8KB  |  209 lines

  1. // Profile.lib - Interface to PM's Profile functions: the routines that
  2. // ver.2         deal with /INI files.
  3. //
  4. //
  5. //***** PrfGetApplicationNames(): Get list of app names in an INI file
  6. // SYNTAX: bool PrfGetApplicationNames(int hini,string[] NameList)
  7. // WHERE: hini: Ini file handle, or one of the pre-defined HINI handles
  8. //        NameList: will be created with list of ApplicationNames
  9. // RETURN: 0 for failure, else non-zero for success
  10. //
  11. //
  12. //***** PrfGetKeyNames(): Get list of key name for application
  13. // SYNTAX: bool PrfGetApplicationNames(int hini,string ApplName,string[] NameList)
  14. // WHERE: hini: Ini file handle, or one of the pre-defined HINI handles
  15. //        ApplName: Name of the application these keys are stored under
  16. //        NameList: will be created with list of KeyNames
  17. // RETURN: 0 for failure, else non-zero for success
  18. //
  19. //
  20. //**** PrfOpenProfile(): Open INI file
  21. // SYNTAX: int PrfOpenProfile(int hab,string FileName)
  22. // WHERE: hab: handle anchor block, such as Info().hab
  23. //        FileName: name of ascii .INI file
  24. // RETURN: Return INI handle, or NULL for Failure
  25. // NOTE: the OS2system and user profiles are always open and available
  26. //       as predefined values, and so don't need calls to PrfOpenProfile()
  27. //
  28. //
  29. //**** PrfCloseProfile(): Close INI file
  30. // SYNTAX: bool PrfCloseProfile(int hini)
  31. // WHERE: hini: Ini file handle, or one of the pre-defined HINI handles
  32. // RETURN: False for failure, else TRUE
  33. //
  34. //
  35. //**** PrfQueryProfileSize(): Get size of binary profile data
  36. // SYNTAX: PrfQueryProfileData(int hini,string AppName,string Key,int BufferLen)
  37. // WHERE: hini: Ini file handle, or one of the pre-defined HINI handles
  38. //        AppName: Name of the application these keys are stored under
  39. //        Key: name of key
  40. //        BufferLen: on output is data size
  41. // RETURN: TRUE for success and FALSE for error
  42. // MODIFY: Sets BufferLen to size of data
  43. //
  44. //
  45. //**** PrfQueryProfileData(): Get binary profile data
  46. // SYNTAX: PrfQueryProfileData(int hini,string AppName,string Key,
  47. //                             byte[] Buffer,int BufferLen)
  48. // WHERE: hini: Ini file handle, or one of the pre-defined HINI handles
  49. //        AppName: Name of the application these keys are stored under
  50. //        Key: name of key
  51. //        Buffer: storage for data, must be at least BufferLen big
  52. //        BufferLen: on input is max size of Buffer, on output is data size
  53. // RETURN: TRUE for success and FALSE for error
  54. // MODIFY: Sets BufferLen to size of data
  55. //
  56. //
  57. //**** PrfWriteProfileData(): Write binary profile data
  58. // SYNTAX: PrfWriteProfileData(int hini,string AppName,string KeyName,
  59. //                             byte[] Data,int DataLen)
  60. // WHERE: hini: Ini file handle, or one of the pre-defined HINI handles
  61. //        AppName: Name of the application these keys are stored under
  62. //        KeyName: name of key
  63. //        Data: byte array or BLOb of data to write
  64. //        DataLen: size of data to write
  65. // RETURN: TRUE for success and FALSE for error
  66. //
  67. //
  68. //**** PrfQueryProfileString(): Read string data
  69. // SYNTAX: PrfQueryProfileString(int hini,string AppName,string KeyName,
  70. //                               string DefaultRet,byte[] Buffer,int MaxBuffer)
  71. // WHERE: hini: Ini file handle, or one of the pre-defined HINI handles
  72. //        AppName: Name of the application these keys are stored under
  73. //        KeyName: name of key
  74. //        DefaultRet: String to return if KeyName is not found
  75. //        Buffer: storage for data, must be at least MaxBuffer big
  76. //        MaxBuffer: size of Buffer
  77. // RETURN: Return string length including the null termination character
  78. // MODIFY: Fill buffer with the string
  79. //
  80. //
  81. //**** PrfWriteProfileString(): Write string data
  82. // SYNTAX: PrfQueryProfileString(int hini,string AppName,string Key,string String)
  83. // WHERE: hini: Ini file handle, or one of the pre-defined HINI handles
  84. //        AppName: Name of the application these keys are stored under
  85. //        Key: name of key
  86. //        String: string to write to profile key
  87. // RETURN: TRUE for success and FALSE for error
  88. //
  89. //
  90. //*** PrfQueryProfileInt(): Query profile as an integer
  91. // SYNTAX: PrfQueryProfileInt(int hini,string AppName,string Key,int DefaultRet)
  92. // WHERE: hini: Ini file handle, or one of the pre-defined HINI handles
  93. //        AppName: Name of the application these keys are stored under
  94. //        Key: name of key
  95. //        DefaultRet: value to return if Key not found or not an integer
  96. // RETURN: Integer value of KeyName, or DefaultRet
  97. //
  98. //
  99.  
  100. #define HINI_PROFILE         NULL  // the USER and the SYSTEM profile
  101. #define HINI_USERPROFILE     (-1)
  102. #define HINI_SYSTEMPROFILE   (-2)
  103. #define HINI_USER    HINI_USERPROFILE
  104. #define HINI_SYSTEM  HINI_SYSTEMPROFILE
  105.  
  106. /*******************************************************************
  107.  *********        END OF DESCRIPTION FOR WINSET.LIB        *********
  108.  *******************************************************************/
  109.  
  110. PrfGetApplicationNames(hini,NameList)
  111. {
  112.    for ( _TryBufSize = 5000; ;_TryBufSize += 5000 ) {
  113.       BLObSize(_Buf,_BufSize = _TryBufSize);
  114.       if ( !PrfQueryProfileData(hini,NULL,NULL,_Buf,_BufSize) )
  115.          return 0;
  116.       if ( _BufSize < (_TryBufSize - 1) )
  117.          break;
  118.    }
  119.    // Put all the names found into the namelist array
  120.    for ( _i = 0; _Buf[0]; _i++ ) {
  121.       strcpy(NameList[_i],_Buf);
  122.       _Buf += strlen(_Buf) + 1;
  123.    }
  124.    return(_i);
  125. }
  126.  
  127. PrfGetKeyNames(hini,ApplicationName,NameList)
  128. {
  129.    for ( _TryBufSize = 5000; ;_TryBufSize += 5000 ) {
  130.       BLObSize(_Buf,_BufSize = _TryBufSize);
  131.       if ( !PrfQueryProfileData(hini,ApplicationName,NULL,_Buf,_BufSize) )
  132.          return(0);
  133.       if ( _BufSize < (_TryBufSize - 1) )
  134.          break;
  135.    }
  136.    // Put all the names found into the namelist array
  137.    for ( _i = 0; _Buf[0]; _i++ ) {
  138.       strcpy(NameList[_i],_Buf);
  139.       _Buf += strlen(_Buf) + 1;
  140.    }
  141.    return(_i);
  142. }
  143.  
  144. PrfQueryProfileData(hini,AppName,Key,Buffer,BufferLen)
  145. {
  146.    #define ORD_PRF32QUERYPROFILEDATA   117
  147.  
  148.    BLObPut(_BufferLen,BufferLen,UWORD32);
  149.    _ret = DynamicLink("PMSHAPI",ORD_PRF32QUERYPROFILEDATA,BIT32,CDECL,
  150.                       hini,AppName,Key,Buffer,_BufferLen);
  151.    BufferLen = BLObGet(_BufferLen,0,UWORD32);
  152.    return(_ret);
  153. }
  154.  
  155. PrfQueryProfileInt(hini,AppName,Key,DefaultRet)
  156. {
  157.    #define ORD_PRF32QUERYPROFILEINT 114
  158.    return DynamicLink("PMSHAPI",ORD_PRF32QUERYPROFILEINT,BIT32,CDECL,
  159.                       hini,AppName,Key,DefaultRet);
  160. }
  161.  
  162. PrfQueryProfileSize(hini,AppName,KeyName,DataLen)
  163. {
  164.    #define ORD_PRF32QUERYPROFILESIZE   101
  165.  
  166.    BLObPut(_DataLen,0,UWORD32);
  167.    _ret = DynamicLink("PMSHAPI",ORD_PRF32QUERYPROFILESIZE,BIT32,CDECL,
  168.                       hini,AppName,KeyName,_DataLen);
  169.    DataLen = BLObGet(_DataLen,0,UWORD32);
  170.    return(_ret);
  171. }
  172.  
  173. PrfQueryProfileString(hini,AppName,KeyName,DefaultRet,Buffer,MaxBuffer)
  174. {
  175.    // if Buffer is not big enough then make it bigger
  176.    if ( !defined(Buffer)  ||  MaxBuffer < BLObSize(Buffer) )
  177.       BLObSize(Buffer,MaxBuffer);
  178.    #define ORD_PRF32QUERYPROFILESTRING 115
  179.    return DynamicLink("PMSHAPI",ORD_PRF32QUERYPROFILESTRING,BIT32,CDECL,
  180.                       hini,AppName,KeyName,DefaultRet,Buffer,MaxBuffer);
  181. }
  182.  
  183. PrfWriteProfileData(hini,AppName,KeyName,Data,DataLen)
  184. {
  185.    #define ORD_PRF32WRITEPROFILEDATA   118
  186.    return DynamicLink("PMSHAPI",ORD_PRF32WRITEPROFILEDATA,BIT32,CDECL,
  187.                       hini,AppName,KeyName,Data,DataLen);
  188. }
  189.  
  190. PrfWriteProfileString(hini,AppName,KeyName,String)
  191. {
  192.    #define ORD_PRF32WRITEPROFILESTRING 116
  193.    return DynamicLink("PMSHAPI",ORD_PRF32WRITEPROFILESTRING,BIT32,CDECL,
  194.                       hini,AppName,KeyName,String);
  195. }
  196.  
  197. PrfOpenProfile(hab,FileName)
  198. {
  199.    #define ORD_PRF32OPENPROFILE  102
  200.    return DynamicLink("PMSHAPI",ORD_PRF32OPENPROFILE,BIT32,CDECL,hab,FileName);
  201. }
  202.  
  203. PrfCloseProfile(hini)
  204. {
  205.    #define ORD_PRF32CLOSEPROFILE 103
  206.    return DynamicLink("PMSHAPI",ORD_PRF32CLOSEPROFILE,BIT32,CDECL,hini);
  207. }
  208.  
  209.