[Original] Use masm32 to operate 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.