PrfWriteProfileData: Difference between revisions
No edit summary |
|||
Line 2: | Line 2: | ||
==Syntax== | ==Syntax== | ||
PrfWriteProfileData(hini, pszApp, pszKey, pData, ulDataLen) | PrfWriteProfileData(HINI ''hini'', PSZ ''pszApp'', PSZ ''pszKey'', PVOID ''pData'', ULONG ''ulDataLen'') | ||
=== Parameters === | === Parameters === |
Revision as of 21:27, 21 November 2023
This function writes a string of binary data into the specified profile.
Syntax
PrfWriteProfileData(HINI hini, PSZ pszApp, PSZ pszKey, PVOID pData, ULONG ulDataLen)
Parameters
- HINI hini (input)
- Initialization-file handle.
- HINI_PROFILE
- User profile
- HINI_USERPROFILE
- User profile
- HINI_SYSTEMPROFILE
- System profile
- Other
- Initialization-file handle returned by PrfOpenProfile.
- PSZ pszApp (input)
- Application name.
- The case-dependent name of the application for which profile data is to be written. Names starting with the characters "PM_" are reserved for system use.
- PSZ pszKey (input)
- Key name.
- The case-dependent name of the key for which profile data is to be written.
- This parameter can be NULL in which case all the pszKey or pData pairs associated with pszApp are deleted.
- PVOID pData (input)
- Value data.
- This is the value of the pszKey or pData pair that is written to the profile. It is not zero-terminated, and its length is given by the ulDataLen parameter.
- If this parameter is NULL, the data associated with the pszKey parameter is deleted.
- ULONG ulDataLen (input)
- Size of value data.
- The size of the data to be written. This length should not exceed 64K bytes.
Returns
- rc (BOOL) - returns
- Success indicator.
- TRUE
- Successful completion
- FALSE
- Error occurred.
Errors
Possible returns from WinGetLastError:
- PMERR_INVALID_PARM (0x1303)
- A parameter to the function contained invalid data.
- PMERR_CAN_NOT_CALL_SPOOLER (0x130D)
- An error occurred attempting to call the spooler validation routine. This error is not raised if the spooler is not installed.
Remarks
If there is no application field in the file that matches the pszApp, a new application field is created before the pszKey or pszData entry is made.
If the key name does not exist for the application, a new pszKey or pszData entry is created for that application. If the pszKey already exists in the file, the existing value is overwritten.
Because of the binary nature of the data, the input data is not zero-terminated. Thus, the length provided is the only way to identify the length of the data.
The maximum size of data that can be associated with a key name is 64K bytes. Data in excess of 64K bytes may be written, but there is no mechanism for retrieving all the data.
Deleting Profile Information
To remove the data associated with a given pszKey value for an application, specify a NULL value for pData and a zero length in ulDataLen.
To remove all the data associated with a particular application, use a pszKey value of NULL, a pData value of NULL, and a ulDataLen value of 0.
To remove ALL the data in a user profile, set pszName, pszKey, and pData to NULL, and set ulDataLen to zero.
Sample Code
This function writes, and subsequently reads, the profile data associated with application SAMPLE.EXE.
/* Write and read binary data to a profile. Some return code */ /* checking omitted for brevity. */ #define INCL_WINSHELLDATA #define INCL_WINERRORS #define INCL_DOSERRORS #include <os2.h> #include <stdio.h> #include <string.h> #define BUFSIZE 7 INT main(VOID) { HAB hab = NULLHANDLE; /* Window handle */ HINI hini = NULLHANDLE; /* INI file handle */ PSZ pszFileName = "PROFILE.INI"; /* Name of profile */ BOOL rc = FALSE; /* Return code */ PSZ pszAppName = "SAMPLE.EXE"; /* Application name */ PSZ pszKeyName = "BINARY_DATA"; /* Data key name */ APIRET ret = NO_ERROR; /* API return code */ PBYTE pData = NULL; /* Pointer to data buffer */ ULONG ulDataSize = 0; /* Size of data to read */ INT idx = 0; /* Loop index */ hab = WinInitialize( 0 ); hini = PrfOpenProfile( hab, pszFileName ); /* Open INI file */ /* Allocate Memory for binary data to be written and read */ ret = DosAllocMem( (PPVOID)&pData, sizeof(BYTE)*80, (ULONG)PAG_COMMIT | PAG_READ | PAG_WRITE ); /* Initialize binary data and then write it to profile */ for(idx = 0; idx < BUFSIZE; idx++) { pData[idx] = idx+65; } rc = PrfWriteProfileData( hini, pszAppName, pszKeyName, (PVOID)pData, (ULONG)BUFSIZE ); if(rc == FALSE) { printf("PrfWriteProfileData error code: %X\n", WinGetLastError(hab)); return 1; } /* Put junk in buffer so we can see if read is successful */ for(idx = 0; idx < BUFSIZE; idx++) { pData[idx] = idx; } /* Retrieve size of data and then get data */ rc = PrfQueryProfileSize( hini, pszAppName, pszKeyName, &ulDataSize ); rc = PrfQueryProfileData( hini, pszAppName, pszKeyName, (PVOID)pData, &ulDataSize); if(rc==FALSE) { printf("PrfQueryProfileData error code: %X\n", WinGetLastError(hab)); return 1; } printf("Profile Data Read:"); for(idx=0; idx < ulDataSize; idx++) printf("%c", pData[idx]); printf("\n"); PrfCloseProfile(hini); /* Close profile */ DosFreeMem(pData); /* Free memory */ return NO_ERROR; /* Phone home <g> */ }