Jump to content

PrfQueryProfileInt: Difference between revisions

From EDM2
m Created page with "==PrfQueryProfileInt== ===Syntax=== lRC = PrfQueryProfileInt( ''hini'', ''pszAppName'', ''pszKeyWord'', ''lDefault'' ); ===Parameters=== ; HINI ''hini'' (input) : Handle to p..."
 
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==PrfQueryProfileInt==
==Syntax==
 
PrfQueryProfileInt( HINI ''hini'', PSZ ''pszAppName'', PSZ ''pszKeyWord'', LONG ''lDefault'' )
===Syntax===
 
lRC = PrfQueryProfileInt( ''hini'', ''pszAppName'', ''pszKeyWord'', ''lDefault'' );


===Parameters===
===Parameters===
 
;''hini'' (HINI) - input: Handle to profile to be searched for data. This may be one of the following:
; HINI ''hini'' (input)
::HINI_PROFILE - Search both the USER and SYSTEM profiles.
: Handle to profile to be searched for data. This may be one of the following:  
::HINI_USERPROFILE - Search only the USER profile.
{| border="1"
::HINI_SYSTEMPROFILE - Search only the SYSTEM profile.
| HINI_PROFILE
::a variable - Search a program-defined profile. This is a HINI returned by PrfOpenProfile().
| Search both the USER and SYSTEM profiles.
;''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.
| HINI_USERPROFILE
;''lDefault'' (LONG) - input: The value of lDefault is returned if the application/keyword pair cannot be located in the specified profile.
| 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().
|}
; 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===
 
; ''lRC'' (LONG) - return: This return value is the result of searching for the application/keyword pair in the specified profile. It may be:
; LONG lRC
::0 - The data associated with the application and keyword is not an integer.
: This return value is the result of searching for the application/keyword pair in the specified profile. It may be:  
::lDefault - The last parameter of PrfQueryProfileInt() is returned to you if the application or keyword could not be found in the profile.
{| border="1"
::otherwise - The value associated with the application/keyword pair is returned.
| 0
If lDefault, you may use WinGetLastError() to find out what went wrong. Possible errors PrfQueryProfileInt() may incur:
| The data associated with the application and keyword is not an integer.
: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.
| lDefault
:PMERR_CAN_NOT_CALL_SPOOLER - 0x130D - An error related to the spooler occurred. (?)
| 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:
{| border="1"
| 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===
  #define INCL_WINSHELLDATA
  #define INCL_WINSHELLDATA
or
or
Line 67: Line 31:


===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===
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.
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.


Line 103: Line 63:


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


PrfQueryProfileData, PrfWriteProfileString
[[Category:Prf]]
 
[[Category:The_OS/2_API_Project]]

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