-------------------------------------------------- ----------------------------- Overview Overview In the program, you often use the set or other small amount of data in the deployment, so that the program is next time You can use it, such as saving the location, size, some user settings of the window, etc., when programmed under DOS, we usually generate a file, write these data to the file In, then read it again in the next execution. In Win32 programming, you can also do this, but Windows has provided us with two convenient methods, which is to save a small amount of data using the registry or INI file (Profile). This article first introduces the use of .ini files. The INI file is the text file, the middle data format is generally: [section1 name] keyname1 = value1keyname2 = value1 = value1key = value1 = value1keyname2 = value2ini file can be divided into several sections, each section name is used [] It is enclosed in a section, there can be many keys, each Key can have a value and occupy a row, the format is key = value, Win32's API for the INI file operation, is a part of Win.ini, Part is part of the user-defined INI file operation. Win.IN and System.ini are two very important initialization files of Windows, and Windows records the selection made by the user and various changes in the system information in these two files. System.ini describes the current state of the system hardware, and the Win.ini file contains the current configuration of the Windows system running environment.
Due to the importance and commonality of Win.ini files, Win32 has an API that operates in Win.ini, which is: getProfileint - get a key value from a section of the win.ini file, its original shape is : GetProfileint (LPCTSTR LPAPPNAME, "pointing to the string address containing the section name LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTOTER ST NDEFAULT // If the key value is not found, if the key value is not found, if it returns the default value); if If the key value is not found, the return value is the default value specified by nDefault. If the value in the key is negative, it returns 0, if the key specifies the mixing of the numbers and strings, returns the value of the digital portion, such as X = 1234ABCD, returns 1234GetProfileString - get a key string from a section of the win.ini file, its original shape is: getProfileString (LPCTSTR LPAPPNAME, point to the string address containing the section name LPCTSTSTR LPKEYNAME, / / Point to include address LPCTSTR lpDefault Key string name, // If a Key value is not found, then the address LPTSTR lpReturnedString return the default string, the address string // return the buffer length of the buffer DWORD nSize //); return In the buffer, the returned EAX value is the length of the returned string (0) GetProfileeSection - reads the entire section from the win.ini file, its original shape is: getProfilesection (LPCTSTR LPAPPNAME, / / Points to the string address of the SECTION name, LPTSTR LPRETURNEDSTRING, / / Return data buffer address DWORD nsize // Return the buffer length of the data); WriteProfileSection - Write the value of the entire section to the specified section of the Win.ini file Section In, its original shape is: WriteProfileSection (lpctstr lpappname, // pointing to string address containing the section name LPCTS Tr lpstring // The address of the data to be written); if Win.ini does not specify the section, the API will create a newly established and write data. If it already exists, first remove all the key in the original Secit, and write new of. WriteProfileString - Write a Key value in the specified section of the Win.ini file, its original shape is: WriteProfileString (LPCTSTR LPAPPNAME, // Point to the string address lpctstr lpkeyName containing the section name, // Point to the string address containing the KEY name LPCTSTSTR LPSTRING // The string address to be written; if Win.ini does not have the specified section, the API will create a new section. If there is no specified key, create a new key and write data, if already existing, use the string instead of the original Value.
The above API is working for Win.ini. Of course, for us, more is to build your own INI file in the directory running, if you need to operate your own INI file, you will use another Group API, this set of APIs and tops, as long as the above set of Profile can be replaced with privateprofile (private), the parameters of an INI file name are also corresponding to the parameters. For example GetPrivateProfileInt, GetPrivateProfileSection, WritePrivateProfileString the like, the following were introduced: GetPrivateProfileInt - obtaining a key from a file INI Section integer value, which is the prototype: GetPrivateProfileInt (LPCTSTR lpAppName, // Section to a string containing the name of the address LPCTSTR LPKEYNAME, / / Point to the string address containing the key name INT ndefault // If the key value is not found, the default value is the file name of the LPCTSTR LPFILENAME // INI file); the definition of the middle parameter and the return value and getProfileint it's the same. GetPrivateProfileString - gets a key string from a section of the INI file, its original shape is: getPrivateProfileString (LPCTSTR LPAPPNAME, "pointing to a string address lpctstr lpkeyName containing the section name, // Point to the string address containing the KEY name LPCTSTR LPDEFAULT, // If the key value is not found, the default string is returned LPTSTR LPRETURNEDSTRING, / / Returns the buffer address of the buffer address DWORD nsize // Buffer LPCTSTSTR LPFILENAME // INI file name); GetPrivateProfileSECTION - Reads the entire section from the INI file, its original shape is: getPrivateProfileSection (LPCTSTR LPAPPNAME, "pointing to a string address containing the section name LPTSTSTSTSTSTSTSTSTSTSTURTURNEDSTRING, / / Return data buffer address DWORD nsize // Return data The file name of the buffer length LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTATIONS: This API can read the entire section, when you don't know which Key is in section, you can use this API to read the entire section and then processed.