📄 macros.inc
字号:
sval MACRO lpstring ; string to signed 32 bit integer
invoke atol, reparg(lpstring)
EXITM <eax>
ENDM
uval MACRO lpstring ; string to unsigned 32 bit integer
invoke atodw, reparg(lpstring)
EXITM <eax>
ENDM
val equ <uval>
hval MACRO lpstring ; hex string to unsigned 32 bit integer
invoke htodw, reparg(lpstring)
EXITM <eax>
ENDM
; ********************************
; BASIC string function emulation
; ********************************
add$ MACRO lpSource,lpAppend
invoke szCatStr,tstarg(lpSource),reparg(lpAppend)
EXITM <eax>
ENDM
append$ MACRO string,buffer,location
invoke szappend,reparg(string),buffer,location
EXITM <eax>
ENDM
chr$ MACRO any_text:VARARG
LOCAL txtname
.data
txtname db any_text,0
.code
EXITM <OFFSET txtname>
ENDM
ptr$ MACRO buffer
lea eax, buffer
mov WORD PTR [eax], 0
EXITM <eax>
ENDM
len MACRO lpString
invoke szLen,reparg(lpString)
EXITM <eax>
ENDM
istring MACRO spos,lpMainString,lpSubString
invoke InString,spos,reparg(lpMainString),reparg(lpSubString)
EXITM <eax>
ENDM
ucase$ MACRO lpString
invoke szUpper,reparg(lpString)
EXITM <eax>
ENDM
lcase$ MACRO lpString
invoke szLower,reparg(lpString)
EXITM <eax>
ENDM
left$ MACRO lpString,slen
invoke szLeft,reparg(lpString),reparg(lpString),slen
EXITM <eax>
ENDM
right$ MACRO lpString,slen
invoke szRight,reparg(lpString),reparg(lpString),slen
EXITM <eax>
ENDM
rev$ MACRO lpString
invoke szRev,reparg(lpString),reparg(lpString)
EXITM <eax>
ENDM
ltrim$ MACRO lpString
invoke szLtrim,reparg(lpString),reparg(lpString)
mov eax, ecx
EXITM <eax>
ENDM
rtrim$ MACRO lpString
invoke szRtrim,reparg(lpString),reparg(lpString)
mov eax, ecx
EXITM <eax>
ENDM
trim$ MACRO lpString
invoke szTrim,reparg(lpString)
mov eax, ecx
EXITM <eax>
ENDM
remove$ MACRO src,substr
invoke szRemove,reparg(src),reparg(src),reparg(substr)
EXITM <eax>
ENDM
ustr$ MACRO DDvalue ;; unsigned integer from string
LOCAL rvstring
.data
rvstring db 20 dup (0)
align 4
.code
;; invoke dwtoa,DDvalue,ADDR rvstring
invoke crt__ultoa,DDvalue,ADDR rvstring,10
EXITM <OFFSET rvstring>
ENDM
sstr$ MACRO DDvalue ;; signed integer from string
LOCAL rvstring
.data
rvstring db 20 dup (0)
align 4
.code
invoke dwtoa,DDvalue,ADDR rvstring
;; invoke ltoa,DDvalue,ADDR rvstring
EXITM <OFFSET rvstring>
ENDM
uhex$ MACRO DDvalue ;; unsigned DWORD to hex string
LOCAL rvstring
.data
rvstring db 12 dup (0)
align 4
.code
invoke dw2hex,DDvalue,ADDR rvstring
EXITM <OFFSET rvstring>
ENDM
comment * -------------------------------------------------------
Each of the following macros has its own dedicated 260
BYTE buffer. The OFFSET returned by each macro can be
used directly in code but if the macro is called again
the data in the dedicated buffer will be overwritten
with the new result.
mov str1, ptr$(buffer)
mov str2, pth$()
invoke szCopy str2,str1
Empty brackets should be used with these macros as they
take no parameters. pth$() CurDir$() etc ...
------------------------------------------------------- *
pth$ MACRO ;; application path OFFSET returned
IFNDEF pth__equate__flag
.data?
pth__260_BYTE__buffer db MAX_PATH dup (?)
.code
pth__equate__flag equ <1>
ENDIF
invoke GetAppPath,ADDR pth__260_BYTE__buffer
EXITM <eax>
ENDM
CurDir$ MACRO
IFNDEF cdir__equate__flag
.data?
cdir__260_BYTE__buffer db MAX_PATH dup (?)
.code
cdir__equate__flag equ <1>
ENDIF
invoke GetCurrentDirectory,MAX_PATH,ADDR cdir__260_BYTE__buffer
mov eax, OFFSET cdir__260_BYTE__buffer
EXITM <eax>
ENDM
SysDir$ MACRO
IFNDEF sys__equate__flag
.data?
sysdir__260_BYTE__buffer db MAX_PATH dup (?)
.code
sys__equate__flag equ <1>
ENDIF
invoke GetSystemDirectory,ADDR sysdir__260_BYTE__buffer,MAX_PATH
mov eax, OFFSET sysdir__260_BYTE__buffer
EXITM <eax>
ENDM
WinDir$ MACRO
IFNDEF wdir__equate__flag
.data?
windir__260_BYTE__buffer db MAX_PATH dup (?)
.code
wdir__equate__flag equ <1>
ENDIF
invoke GetWindowsDirectory,ADDR windir__260_BYTE__buffer,MAX_PATH
mov eax, OFFSET windir__260_BYTE__buffer
EXITM <eax>
ENDM
; ---------------------------------------------------------------
; Get command line arg specified by "argnum" starting at arg 1
; Test the return values with the following to determine results
; 1 = successful operation
; 2 = no argument exists at specified arg number
; 3 = non matching quotation marks
; 4 = empty quotation marks
; test the return value in ECX
; ---------------------------------------------------------------
cmd$ MACRO argnum
LOCAL argbuffer
IFNDEF cmdflag
.data?
argbuffer db MAX_PATH dup (?)
.code
cmdflag equ 1
ENDIF
invoke GetCL,argnum, ADDR argbuffer
mov ecx, eax
mov eax, OFFSET argbuffer
EXITM <eax>
ENDM
; ******************************************
; DOS style directory manipulation macros *
; The parameters passed to these directory *
; macros should be zero terminated string *
; addresses. *
; ******************************************
chdir MACRO pathname
invoke SetCurrentDirectory,reparg(pathname)
ENDM
CHDIR equ <chdir>
mkdir MACRO dirname
invoke CreateDirectory,reparg(dirname),NULL
ENDM
MKDIR equ <mkdir>
rndir MACRO oldname,newname
invoke MoveFile,reparg(oldname),reparg(newname)
ENDM
RNDIR equ <rndir>
rmdir MACRO dirname
invoke RemoveDirectory,reparg(dirname)
ENDM
RMDIR equ <rmdir>
; **************************
; memory allocation macros *
; **************************
comment * --------------------------------------------------
Two macros for allocating and freeing OLE memory.
stralloc returns the handle/address of the string
memory in eax. alloc$ acts in the same way but is
used in the function position. strfree uses the
handle to free memory after use.
NOTE that you must use the following INCLUDE &
LIB files with these two macros.
include \MASM32\include\oleaut32.inc
includelib \MASM32\LIB\oleaut32.lib
-------------------------------------------------- *
alloc$ MACRO ln
invoke SysAllocStringByteLen,0,ln
mov BYTE PTR [eax], 0
EXITM <eax>
ENDM
free$ MACRO strhandle
invoke SysFreeString,strhandle
ENDM
stralloc MACRO ln
invoke SysAllocStringByteLen,0,ln
ENDM
strfree MACRO strhandle
invoke SysFreeString,strhandle
ENDM
comment * ------------------------------------------------
The following 2 macros are for general purpose memory
allocation where fine granularity in memory is required
or where the memory attribute "execute" is useful.
------------------------------------------------------ *
alloc MACRO bytecount
invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,bytecount
EXITM <eax>
ENDM
free MACRO hmemory
invoke GlobalFree,hmemory
ENDM
comment * ---------------------------------------------------------
Heap allocation and deallocation macros. On later versions
of Windows HeapAlloc() appears to be faster on small
allocations than GlobalAlloc() using the GMEM_FIXED flag.
--------------------------------------------------------- *
halloc MACRO bytecount
EXITM <rv(HeapAlloc,rv(GetProcessHeap),0,bytecount)>
ENDM
hsize MACRO hmem
invoke HeapSize,rv(GetProcessHeap),0,hmem
EXITM <eax>
ENDM
hfree MACRO memory
invoke HeapFree,rv(GetProcessHeap),0,memory
ENDM
; ************************************************************
; File IO macros *
; NOTE: With the address returned by InputFile that contains *
; the data in the file, it must be deallocated using the API *
; function GlobalFree(). *
; EXAMPLE: invoke GlobalFree,pMem *
; ************************************************************
InputFile MACRO lpFile
;; ----------------------------------------------------------
;; The untidy data? names are to avoid duplication in normal
;; code. The two values are reused by each call to the macro
;; ----------------------------------------------------------
IFNDEF ipf@@flag ;; if the flag is not defined
.data?
ipf@__@mem@__@Ptr dd ? ;; write 2 DWORD variables to
ipf@__file__@len dd ? ;; the uninitialised data section
.code
ipf@@flag equ <1> ;; define the flag
ENDIF
invoke read_disk_file,reparg(lpFile),
ADDR ipf@__@mem@__@Ptr,
ADDR ipf@__file__@len
mov ecx, ipf@__file__@len ;; file length returned in ECX
mov eax, ipf@__@mem@__@Ptr ;; address of memory returned in EAX
EXITM <eax>
ENDM
OutputFile MACRO lpFile,lpMem,lof
invoke write_disk_file,reparg(lpFile),lpMem,lof
EXITM <eax>
ENDM
; -----------------------------------------
; common dialog file open and close macros.
; Return value in both is the OFFSET of a
; 260 byte dedicated buffer in the .DATA?
; section in EAX.
; -----------------------------------------
OpenFileDlg MACRO hWin,hInstance,lpTitle,lpPattern
invoke OpenFileDialog,hWin,hInstance,reparg(lpTitle),reparg(lpPattern)
EXITM <eax>
ENDM
SaveFileDlg MACRO hWin,hInstance,lpTitle,lpPattern
invoke SaveFileDialog,hWin,hInstance,reparg(lpTitle),reparg(lpPattern)
EXITM <eax>
ENDM
; ----------------------------------------------------------
; load a library and get the procedure address in one macro
; return value for the proc address in in EAX. Both DLL and
; procedure name are enclosed in quotation marks.
;
; EXAMPLE : LoadProcAddress "mydll.dll","myproc"
; proc address in EAX
; library handle in ECX
;
; EXAMPLE : mov lpProc, GetDllProc("mydll.dll","myproc")
; library handle in ECX
; ----------------------------------------------------------
LoadProcAddress MACRO libname_text1,procname_text2
LOCAL library_name
LOCAL proc_name
.data
library_name db libname_text1,0
proc_name db procname_text2,0
align 4
.code
invoke LoadLibrary,ADDR library_name
mov ecx, eax
invoke GetProcAddress,eax,ADDR proc_name
ENDM
GetDllProc MACRO libname_text1,procname_text2
LOCAL library_name
LOCAL proc_name
.data
library_name db libname_text1,0
proc_name db procname_text2,0
align 4
.code
invoke LoadLibrary,ADDR library_name
mov ecx, eax
invoke GetProcAddress,eax,ADDR proc_name
EXITM <eax>
ENDM
; **********************************
; control flow macro by Greg Falen *
; **********************************
; ----------------------
; Switch/Case emulation
; ----------------------
$casflg equ <>
$casvar equ <>
$casstk equ <>
switch macro _var:req, _reg:=<eax>
mov _reg, _var
$casstk catstr <_reg>, <#>, $casflg, <#>, $casstk
$casvar equ _reg
$casflg equ <0> ;; 0 = emit an .if, 1 an .elseif
endm
case macro _args:vararg ;; like Pascal: case id1. id4 .. id8, lparam, ...
;; does an or (case1 || case2 || case3...)
$c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -