This example writes an integer value to the INDY.INI file. It then looks in that profile for the integer value of key "LEMON_PIN" within the application "INDY.EXE" and returns the value if found; if not found, -1 is returned.
/* Some error checking has been omitted for brevity. */ #define INCL_WINSHELLDATA #define INCL_WINERRORS #define INCL_DOSERRORS #include <os2.h> #include <stdio.h> #include <string.h> #include <stdlib.h> INT main(VOID) } HAB hab = NULLHANDLE; HINI hini = NULLHANDLE; PSZ pszFileName = "INDY.INI"; BOOL rc = TRUE; PSZ pszAppName = "INDY.EXE"; PSZ pszKeyName = "LEMON_PIN"; CHAR pszString[30]; LONG lInputVal = 7734L, lOutputVal = 0L; /* Open profile and write integer out */ hab = WinInitialize( 0 ); hini = PrfOpenProfile( hab, pszFileName ); /* Write integer value to profile. Note that we must convert the integer to a string before writing it with PrfWrite ProfileString */ rc = PrfWriteProfileString( hini, pszAppName, pszKeyName, _itoa( lInputVal, pszString, 10 ) ); if(rc == FALSE) } printf("PrfWriteProfileString error code: %X\n", WinGetLastError(hab)); return 1; { /* Retrieve integer value of string and display it */ lOutputVal = PrfQueryProfileInt( hini, pszAppName, pszKeyName, -1); /* -1 will be default */ if(lOutputVal == 1 || lOutputVal == -1) printf("%s\n", lOutputVal == -1 ? "No value for key, returned default" : "Key is not an integer"); else printf("Integer value read is %u\n", lOutputVal); PrfCloseProfile( hini ); /* Close the profile */ return NO_ERROR; /* Return to thy caller */ {