; <
: Filename: ini-demo.asm
; Function: Demo the operation of INI File
; Author: Purple endurer
;
; Log
==================================
; Created!
; <
. 386
. Model flat, stdcall
Option Casemap: None
Include/masm32/include/Windows. inc
Include/masm32/include/kernel32.inc
Include/masm32/include/user32.inc
Includelib/masm32/lib/user32.lib
Includelib/masm32/lib/kernel32.lib
M_msgbox macro lpstrmsg, dwicon
Invoke MessageBox, null, lpstrmsg, ADDR g_szmsgcaption, dwicon
Endm
. Data
G_szmsgcaption DB "ini Demo", 0
G_szinifilespec DB "./test. ini", 0
G_szkeyfilename DB "FILENAME", 0
G_szkeyfilesize DB "filesize", 0
G_szsectinfo DB "info", 0
G_szfmt4int DB "% s value: % d", 0
G_szfailreadkey DB "fail to read key! ", 0
G_szfailwritestr DB "fail to write string! ", 0
G_szone DB "1", 0
. Data?
G_szbuf dB 256 DUP (?)
. Code
Start:
; Getprivateprofilestring-obtains a key string from a section of the INI file. Its original form is:
; Getprivateprofilestring (
; Lpctstr lpappname, // point to the string address containing the section name
; Lpctstr lpkeyname, // point to the string address containing the key name
; Lptstr lpdefault, // if the key value is not found, copy the default string to the buffer of the returned string. The value cannot be null.
; Lptstr lpreturnedstring, // return the buffer address of the string
; DWORD nsize // buffer Length
; Lptstr lpfilename // INI File Name
Invoke getprivateprofilestring, ADDR g_szsectinfo, ADDR g_szkeyfilename, ADDR g_szfailreadkey, ADDR g_szbuf, sizeof g_szbuf, ADDR g_szinifilespec
M_msgbox ADDR g_szbuf, mb_iconerror
; Getprivateprofileint-obtains an integer of the key from a section in the INI file. Its original form is:
;
; Getprivateprofileint (
; Lpctstr lpappname, // point to the string address containing the section name
; Lpctstr lpkeyname, // point to the string address containing the key name
; Int ndefault // if the key value is not found, the default value is returned.
; Lptstr lpfilename // INI File Name
Invoke getprivateprofileint, ADDR g_szsectinfo, ADDR g_szkeyfilesize, 0, ADDR g_szinifilespec
Invoke wsprintf, ADDR g_szbuf, ADDR g_szfmt4int, ADDR g_szkeyfilesize, eax
M_msgbox ADDR g_szbuf, mb_iconerror
; Writeprivateprofilestring-write a key value to the specified section of the INI file. Its prototype is:
; Writeprivateprofilestring (
; Lpctstr lpappname, // point to the string address containing the section name
; Lpctstr lpkeyname, // point to the string address containing the key name
; Lpctstr lpstring // string address to be written
; Lptstr lpfilename // INI file name. If the file does not exist, the system automatically creates
Invoke writeprivateprofilestring, ADDR g_szsectinfo, ADDR g_szkeyfilename, ADDR g_szmsgcaption, ADDR g_szinifilespec
. If eax = NULL
M_msgbox ADDR g_szfailwritestr, mb_iconerror
. Endif
Invoke writeprivateprofilestring, ADDR g_szsectinfo, ADDR g_szkeyfilesize, ADDR g_szone, ADDR g_szinifilespec
. If eax = NULL
M_msgbox ADDR g_szfailwritestr, mb_iconerror
. Endif
Invoke exitprocess, null
End start