Jump to content

PrfQueryProfileInt: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==PrfQueryProfileInt==
==Syntax==
===Syntax===
PrfQueryProfileInt( HINI ''hini'', PSZ ''pszAppName'', PSZ ''pszKeyWord'', LONG ''lDefault'' )
lRC = PrfQueryProfileInt( ''hini'', ''pszAppName'', ''pszKeyWord'', ''lDefault'' );


===Parameters===
===Parameters===
; HINI ''hini'' (input)
;''hini'' (HINI) - input: Handle to profile to be searched for data. This may be one of the following:
: Handle to profile to be searched for data. This may be one of the following:
::HINI_PROFILE - Search both the USER and SYSTEM profiles.
{|class="wikitable"
::HINI_USERPROFILE - Search only the USER profile.
!HINI_PROFILE
::HINI_SYSTEMPROFILE - Search only the SYSTEM profile.
|Search both the USER and SYSTEM profiles.
::a variable - Search a program-defined profile. This is a HINI returned by PrfOpenProfile().
|-
;''pszAppName'' (PSZ) - input: Pointer to a null-terminated string that holds the application name to search for within the profile. This string is case-sensitive.
!HINI_USERPROFILE
;''pszKeyWord'' (PSZ) - input: Pointer to a null-terminated string that holds the keyword name to search for within the application name specified. This is case-sensitive as well.
|Search only the USER profile.
;''lDefault'' (LONG) - input: The value of lDefault is returned if the application/keyword pair cannot be located in the specified profile.
|-
!HINI_SYSTEMPROFILE
|Search only the SYSTEM profile.
|-
!a variable
|Search a program-defined profile. This is a HINI returned by PrfOpenProfile().
|}
 
; PSZ ''pszAppName'' (input)
: Pointer to a null-terminated string that holds the application name to search for within the profile. This string is case-sensitive.
; PSZ ''pszKeyWord'' (input)
: Pointer to a null-terminated string that holds the keyword name to search for within the application name specified. This is case-sensitive as well.
; LONG ''lDefault'' (input)
: The value of lDefault is returned if the application/keyword pair cannot be located in the specified profile.


===Returns===
===Returns===
; LONG lRC
; ''lRC'' (LONG) - return: This return value is the result of searching for the application/keyword pair in the specified profile. It may be:
: This return value is the result of searching for the application/keyword pair in the specified profile. It may be:  
::0 - The data associated with the application and keyword is not an integer.
{|class="wikitable"
::lDefault - The last parameter of PrfQueryProfileInt() is returned to you if the application or keyword could not be found in the profile.
| 0
::otherwise - The value associated with the application/keyword pair is returned.
| The data associated with the application and keyword is not an integer.
If lDefault, you may use WinGetLastError() to find out what went wrong. Possible errors PrfQueryProfileInt() may incur:
|-
:PMERR_INVALID_PARM - 0x1303 - One of the parameters to PrfQueryProfileData() was invalid.
| lDefault
:PMERR_NOT_IN_IDX - 0x1304 - The application name, keyword, or program handle was not found.
| The last parameter of PrfQueryProfileInt() is returned to you if the application or keyword could not be found in the profile.
:PMERR_CAN_NOT_CALL_SPOOLER - 0x130D - An error related to the spooler occurred. (?)
|-
| otherwise
| The value associated with the application/keyword pair is returned.
|}If lDefault, you may use WinGetLastError() to find out what went wrong. Possible errors PrfQueryProfileInt() may incur:
{|class="wikitable"
| PMERR_INVALID_PARM
| 0x1303
| One of the parameters to PrfQueryProfileData() was invalid.
|-
| PMERR_NOT_IN_IDX
| 0x1304
| The application name, keyword, or program handle was not found.
|-
| PMERR_CAN_NOT_CALL_SPOOLER
| 0x130D
| An error related to the spooler occured. (?)
|}


===Include Info===
===Include Info===
Line 64: Line 32:
===Usage Explanation===
===Usage Explanation===
The one feature that makes PrfQueryProfileInt() useful is how it interprets data. If you store a long integer as a four byte data type, then you'll have to use PrfQueryProfileData() to retrieve it. However, PrfQueryProfileInt() allows you to store an integer as an ASCII string. For example, if the string "32462" is stored in a profile and PrfQueryProfileInt() is called, it will convert this string to its binary equivalent for you.
The one feature that makes PrfQueryProfileInt() useful is how it interprets data. If you store a long integer as a four byte data type, then you'll have to use PrfQueryProfileData() to retrieve it. However, PrfQueryProfileInt() allows you to store an integer as an ASCII string. For example, if the string "32462" is stored in a profile and PrfQueryProfileInt() is called, it will convert this string to its binary equivalent for you.
===Relevant Structures===


===Gotchas===
===Gotchas===
Line 97: Line 63:


===See Also===
===See Also===
PrfQueryProfileData, PrfWriteProfileString
*[[PrfQueryProfileData]]
*[[PrfWriteProfileString]]


[[Category:The_OS/2_API_Project]]
[[Category:Prf]]

Latest revision as of 03:29, 25 November 2023

Syntax

PrfQueryProfileInt( HINI hini, PSZ pszAppName, PSZ pszKeyWord, LONG lDefault )

Parameters

hini (HINI) - input
Handle to profile to be searched for data. This may be one of the following:
HINI_PROFILE - Search both the USER and SYSTEM profiles.
HINI_USERPROFILE - Search only the USER profile.
HINI_SYSTEMPROFILE - Search only the SYSTEM profile.
a variable - Search a program-defined profile. This is a HINI returned by PrfOpenProfile().
pszAppName (PSZ) - input
Pointer to a null-terminated string that holds the application name to search for within the profile. This string is case-sensitive.
pszKeyWord (PSZ) - input
Pointer to a null-terminated string that holds the keyword name to search for within the application name specified. This is case-sensitive as well.
lDefault (LONG) - input
The value of lDefault is returned if the application/keyword pair cannot be located in the specified profile.

Returns

lRC (LONG) - return
This return value is the result of searching for the application/keyword pair in the specified profile. It may be:
0 - The data associated with the application and keyword is not an integer.
lDefault - The last parameter of PrfQueryProfileInt() is returned to you if the application or keyword could not be found in the profile.
otherwise - The value associated with the application/keyword pair is returned.

If lDefault, you may use WinGetLastError() to find out what went wrong. Possible errors PrfQueryProfileInt() may incur:

PMERR_INVALID_PARM - 0x1303 - One of the parameters to PrfQueryProfileData() was invalid.
PMERR_NOT_IN_IDX - 0x1304 - The application name, keyword, or program handle was not found.
PMERR_CAN_NOT_CALL_SPOOLER - 0x130D - An error related to the spooler occurred. (?)

Include Info

#define INCL_WINSHELLDATA

or

#define INCL_WIN

or

#define INCL_PM
#include <os2.h>

Usage Explanation

The one feature that makes PrfQueryProfileInt() useful is how it interprets data. If you store a long integer as a four byte data type, then you'll have to use PrfQueryProfileData() to retrieve it. However, PrfQueryProfileInt() allows you to store an integer as an ASCII string. For example, if the string "32462" is stored in a profile and PrfQueryProfileInt() is called, it will convert this string to its binary equivalent for you.

Gotchas

Both the application name and the keyword are CASE SENSITIVE. It is recommended that all your references to these strings come from a single source, such as a #define or a global variable, so as not to get tripped up on this. It is recommended that strings are null-terminated to reduce errors, but it seems that PrfQueryProfileInt() will just stop reading the string when it hits a non-numeric character. So, "123xyz" will return 123. The implication is that comma-delimited strings make this function useless. For example, "100,000" will return 100. Obviously, floating point numbers get truncated. Also, the numerics must be the first characters in the string. The one non-numeric character that seems to be allowed is a '-', to signify a negative integer. "-123" returns -123. If there's a possibility that you might pass a zero for the last parameter, or the string should legitimately return a zero, then you should call WinGetLastError() to see if there was a problem.

Sample Code

#define INCL_WINSHELLDATA
#include <os2.h>
#include <stdio.h>

static UCHAR szAppName[] = "MyApp";
static UCHAR szKeyName[] = "MyKey";

int main(void)
{
  HINI hini;
  LONG lRC;

  /* I write this string to give you a basis for experimentation... */
  PrfWriteProfileString(HINI_USER, szAppName, szKeyName, "-100.10,000x");

  /*
   * I specified 2 for the last param, as there's no way a two will get
   *  returned by accident in this experiment.
   */
  lRC = PrfQueryProfileInt(HINI_USER, szAppName, szKeyName, 2);

  printf("PrfQueryProfileInt returned %d\n", lRC);
  return(0);
} /* main */

See Also