Hi everyone!
In Delphi you can do a ShowMessage("Hello World!") to display a simple Messagebox with the specified text. I tried to do something like it in assembly with a macro but my macro skills aren't the best. The macro output should be something like this:
invoke MessageBox,hWin,CTEXT(passed text),CTEXT("Info"),MB_OK
Can someone help me with this one? :confused:
/Delight
In Delphi you can do a ShowMessage("Hello World!") to display a simple Messagebox with the specified text. I tried to do something like it in assembly with a macro but my macro skills aren't the best. The macro output should be something like this:
invoke MessageBox,hWin,CTEXT(passed text),CTEXT("Info"),MB_OK
Can someone help me with this one? :confused:
/Delight
This exists in form of the CTXT Macro and the SADD Macro... Here they are:
[size=12]
; Hutch's SADD Macro
; Use: invoke MessageBox,hwnd,SADD("The Message"),SADD("The Title"),MB_OK
; ---------------------
; literal string MACRO
; ---------------------
literal MACRO quoted_text
LOCAL local_text
.data
local_text db quoted_text,0
.code
EXITM <local_text>
ENDM
; --------------------------------
; string address in INVOKE format
; --------------------------------
SADD MACRO quoted_text
EXITM <ADDR literal(quoted_text)>
ENDM
; --------------------------------
; string OFFSET for manual coding
; USE:
; mov eax, CTXT("Hello")
; push 0
; push eax
; push eax
; push 0
; call MessageBox
; --------------------------------
CTXT MACRO quoted_text
EXITM <offset literal(quoted_text)>
ENDM
instead of using .data/.code in the SADD macro, wouldn't it be better
to do something like (untested)...
?
If this works :), it should be usable from any section, where the
original SADD only works within .code. SADD could be useful in .data
for, say, a string pointer table.
Just wondering.
to do something like (untested)...
literal MACRO quoted_text
LOCAL local_text
_data segment
local_text db quoted_text,0
_data ends
EXITM <local_text>
ENDM
?
If this works :), it should be usable from any section, where the
original SADD only works within .code. SADD could be useful in .data
for, say, a string pointer table.
Just wondering.
You can use this macro (found in Masm32/Macros/Macros.asm -- in Masm32 v7)
Sliver
; --------------------------------------------------------
; MsgBox macro takes 2 parameters, both can be either
; literal text in quotes or addresses of zero terminated
; strings passed with "ADDR szString" where szString is
; a zero terminated string. Note that ADDR is uppercase.
;
; example : MsgBox "Greetings all",ADDR szTitle
; MsgBox ADDR szMessage,"Result"
;
; --------------------------------------------------------
MsgBox MACRO handl, TxtMsg, TxtTitle, styl
LOCAL Msg1
LOCAL Titl
If @InStr(1,<TxtMsg>,<ADDR>) eq 0
If @InStr(1,<TxtTitle>,<ADDR>) eq 0
.data
Msg1 db TxtMsg,0
Titl db TxtTitle,0
.code
invoke MessageBox,handl,ADDR Msg1,ADDR Titl,styl
EXITM
EndIf
EndIf
If @InStr(1,<TxtMsg>,<ADDR>) gt 0
If @InStr(1,<TxtTitle>,<ADDR>) eq 0
.data
Titl db TxtTitle,0
.code
invoke MessageBox,handl,TxtMsg,ADDR Titl,styl
EXITM
EndIf
EndIf
If @InStr(1,<TxtMsg>,<ADDR>) eq 0
If @InStr(1,<TxtTitle>,<ADDR>) gt 0
.data
Msg1 db TxtMsg,0
.code
invoke MessageBox,handl,ADDR Msg1,TxtTitle,styl
EXITM
EndIf
EndIf
If @InStr(1,<TxtMsg>,<ADDR>) gt 0
If @InStr(1,<TxtTitle>,<ADDR>) gt 0
invoke MessageBox,handl,TxtMsg,TxtTitle,styl
EXITM
EndIf
EndIf
ENDM
Sliver
instead of using .data/.code in the SADD macro, wouldn't it be better
to do something like (untested)...
to do something like (untested)...
or this (tested)...
literal MACRO quoted_text
LOCAL local_text, SegName
SegName TEXTEQU @CurSeg
.data
local_text db quoted_text,0
@CurSeg ENDS
SegName SEGMENT
EXITM <local_text>
ENDM
*****************************************
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
;::::::::::::::::::::::::::::::::::::::
MsgBox MACRO hWnd, sMessage, sCaption, uType
; (c) Four-F
local szMessage, Mes, szCaption, Cap
IF @InStr(1, <sMessage>, <!">) EQ 1 ; ; is it a string
.data
IF @InStr(1, <sMessage>, <!"!">) EQ 1 ; for null-string
szMessage db 0
ELSE
szMessage db sMessage, 0
ENDIF
.code
Mes TEXTEQU <addr szMessage>
ELSE ; not a string
.ERR <MsgBox macro ERROR!!! Message must be a string.>
EXITM
ENDIF
IF @InStr(1, <sCaption>, <!">) EQ 1 ; ; is it a string
.data
IF @InStr(1, <sCaption>, <!"!">) EQ 1 ; for null-string
szCaption db 0
ELSE
szCaption db sCaption, 0
ENDIF
.code
Cap TEXTEQU <addr szCaption>
ELSE ; not a string
Cap TEXTEQU <sCaption>
ENDIF
invoke MessageBox, hWnd, Mes, Cap, uType
ENDM
;::::::::::::::::::::::::::::::::::::::::::::::::
.code
start:
MsgBox NULL, "Message with caption.", "Caption", MB_ICONINFORMATION
MsgBox NULL, "Message without caption.", "", MB_OK
MsgBox NULL, "Error Message.", NULL, MB_ICONERROR
MsgBox NULL, "", "Empty message.", MB_ICONEXCLAMATION
ret
;:::::::::::::::::::::::::::::::::::::::::::::::::
end start
But this form not supported yet:
MsgBox NULL, "Message with caption.", addr szCaption, MB_OK
It's very convenient sometimes.
If you want to use previously defined caption or message, for ex.
If you need it you can fix my macro.
Just wondering.