Assembly Learning 3: Operating INI files

Source: Internet
Author: User
Tags key string
; <
: 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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.