...
.else ; CreateService fails
invoke GetLastError
; most likely error is ERROR_SERVICE_EXISTS equ 431h
OutputLBText hListBox_Log, \
CTEXT("ERROR: CreateService failed with System Message:"
OutputSystemErrorMsg hListBox_Log
.endif ; CreateService endif
;=======================================================
; Listbox handling Macros to deal with display issues
;=======================================================
;--------------------------------------------------------------------
; MACRO to format FormatMessage string for display in Listbox
; CarriageFeed/LineReturn is not handled well by Listboxes.
; This macro finds the CF/LR added by FormatMessage and
; null terminates the string.
; Usage: pass system error message in eax, i.e.
; invoke GetLastError
; OutputSystemErrorMsg, hListBox
;--------------------------------------------------------------------
OutputSystemErrorMsg MACRO _hWnd
LOCAL lpFormatMsg
.data?
lpFormatMsg db 64 dup(?) ; max buffer for FormatMessage
.code
invoke FormatMessage, FORMAT_MESSAGE_FROM_SYSTEM, NULL, eax,\
NULL, offset lpFormatMsg, sizeof lpFormatMsg, NULL
cld
push ecx
push edi
mov eax, 0Dh
or ecx, -1
lea edi, offset lpFormatMsg
repne scasb
dec edi
mov byte ptr [edi], 0 ; null terminate the string
pop edi
pop ecx
invoke SendMessage, _hWnd, LB_ADDSTRING, 0, offset lpFormatMsg
invoke SendMessage, _hWnd, LB_ADDSTRING, 0, CTEXT(" "

invoke SendMessage, _hWnd, LB_GETCOUNT, 0, 0
sub eax, 1
invoke SendMessage, _hWnd, LB_SETTOPINDEX, eax, 0
ENDM
;--------------------------------------------------------------------
;--------------------------------------------------------------------
; MACRO to output Listbox text, may include CF/LR and/or variable formatting arguments
; Usage: pass CF/LR as "\n", leave blank if desired if including Args
; OutputLBText hWnd, CTEXT("text"

; OutputLBText hWnd, CTEXT("text"

, \n
; OutputLBText hWnd, CTEXT("text %04X"

, \n, eax
; OutputLBText hWnd, CTEXT("text %04X %04d"

, ,eax, eax
;--------------------------------------------------------------------
OutputLBText MACRO _hWnd, Text, CFLR, Args:VARARG
LOCAL StringBuff
.data?
StringBuff db MAX_PATH dup(?)
.code
push eax
IFNB <Args> ; if 'Args' argument is not blank, format according to Text syntax
invoke wsprintf, offset StringBuff, Text, Args
invoke SendMessage, _hWnd, LB_ADDSTRING, 0,\
offset StringBuff
IFNB <CFLR> ; if 'CFLR' argument is not blank, add a blank line
invoke SendMessage, _hWnd, LB_ADDSTRING, 0, CTEXT(" "

ENDIF
ENDIF
IFB <Args> ; if 'Args' argument is blank, output Text as passed
invoke SendMessage, _hWnd, LB_ADDSTRING, 0, Text
IFNB <CFLR>
invoke SendMessage, _hWnd, LB_ADDSTRING, 0, CTEXT(" "

ENDIF
ENDIF
invoke SendMessage, _hWnd, LB_GETCOUNT, 0, 0
sub eax, 1
invoke SendMessage, _hWnd, LB_SETTOPINDEX, eax, 0
pop eax
ENDM
;--------------------------------------------------------------------
;=======================================================