Anybody know a Win32 API call to display a hex number like text in MessageBox?
E.g: invoke HexNumMessage,0x0d to display 0D in a message box?
Posted on 2003-06-11 07:56:40 by MACi
No such API, but you can use a macro showhex:
;##########################################################################

; macros
;##########################################################################
macro m2m dest,src {
push src
pop dest
}
;##########################################################################
macro showint caption,value {
local .over,.str
jmp .over
.str db caption," = %u",0
.over: pushad
mov ebx,value
stdcall [GlobalAlloc],GMEM_MOVEABLE+GMEM_ZEROINIT,1000h
push eax
push eax
stdcall [GlobalLock],eax
push eax
ccall [wsprintf],eax,OFFSET .str,ebx
pop eax
stdcall [MessageBox],0,eax,0,MB_OK+MB_ICONASTERISK+MB_APPLMODAL
call [GlobalUnlock]
call [GlobalFree]
popad
}
;##########################################################################
macro showhex caption,value {
local .over,.str
jmp .over
.str db caption," = %08Xh",0
.over: pushad
mov ebx,value
stdcall [GlobalAlloc],GMEM_MOVEABLE+GMEM_ZEROINIT,1000h
push eax
push eax
stdcall [GlobalLock],eax
push eax
ccall [wsprintf],eax,OFFSET .str,ebx
pop eax
stdcall [MessageBox],0,eax,0,MB_OK+MB_ICONASTERISK+MB_APPLMODAL
call [GlobalUnlock]
call [GlobalFree]
popad
}
;##########################################################################
macro showstr caption,value {
local .over,.str
jmp .over
.str db caption," = %s",0
.over: pushad
mov ebx,value
stdcall [GlobalAlloc],GMEM_MOVEABLE+GMEM_ZEROINIT,1000h
push eax
push eax
stdcall [GlobalLock],eax
push eax
ccall [wsprintf],eax,OFFSET .str,ebx
pop eax
stdcall [MessageBox],0,eax,0,MB_OK+MB_ICONASTERISK+MB_APPLMODAL
call [GlobalUnlock]
call [GlobalFree]
popad
}
;##########################################################################
macro showfmt fmtstr,[values] {
common local .over,.str,..size
jmp .over
.str db fmtstr,0
.over: pushad
stdcall [GlobalAlloc],GMEM_MOVEABLE+GMEM_ZEROINIT,1000h
push eax
push eax
stdcall [GlobalLock],eax
push eax
..size = 8
reverse
pushd values
..size = ..size+4
common
push OFFSET .str
push eax
call [wsprintf]
add esp,..size
pop eax
stdcall [MessageBox],0,eax,0,MB_OK+MB_ICONASTERISK+MB_APPLMODAL
stdcall [GlobalUnlock]
stdcall [GlobalFree]
popad
}
;##########################################################################
macro lasterr {
pushad
stdcall [GlobalAlloc],GMEM_MOVEABLE+GMEM_ZEROINIT,1000h
push eax
push eax
stdcall [GlobalLock],eax
push eax
call [GetLastError]
stdcall [FormatMessage],FORMAT_MESSAGE_FROM_SYSTEM,0,eax,0,[esp+08h],1000h,0
pop eax
stdcall [MessageBox],0,eax,0,MB_OK+MB_ICONASTERISK+MB_APPLMODAL
call [GlobalUnlock]
call [GlobalFree]
popad
}
;##########################################################################
macro msgbox value {
pushad
stdcall [MessageBox],0,value,0,MB_OK+MB_ICONASTERISK+MB_APPLMODAL
popad
}
;##########################################################################


Use like so:
showhex "accumulator",eax
Posted on 2003-06-11 08:49:53 by comrade
Thanks comrade, I included the macros, but:
flat assembler version 1.46
debug5.asm [133] pushd [19]:
showhex 'accumulator',eax
error: undefined symbol.

:(
Posted on 2003-06-11 12:06:58 by MACi
Did you include stdcall macro file?
Posted on 2003-06-11 16:09:38 by comrade
I included everything, and I'm using stdcall several times in the code!

include '%include%\win32ax.inc'
win32ax.inc :
include '%include%/win32a.inc'
include '%include%/macro/if.inc'
include '%include%/apia/kernel32.inc'
include '%include%/apia/user32.inc'
include '%include%/apia/gdi32.inc'
include '%include%/apia/advapi32.inc'
include '%include%/apia/comctl32.inc'
include '%include%/apia/comdlg32.inc'
include '%include%/apia/shell32.inc'
include '%include%/apia/wsock32.inc'
include '%include%/apia/winmm.inc'
win32a.inc :
include '%include%/macro/stdcall.inc'
include '%include%/macro/cdecl.inc'
include '%include%/macro/import.inc'
include '%include%/macro/export.inc'
include '%include%/macro/resource.inc'
include '%include%/macro/struct.inc'
CHAR equ rb
include '%include%/equates/kernel32.inc'
include '%include%/equates/user32.inc'
include '%include%/equates/gdi32.inc'
include '%include%/equates/comctl32.inc'
include '%include%/equates/comdlg32.inc'
include '%include%/equates/shell32.inc'
include '%include%/equates/wsock32.inc'
Posted on 2003-06-12 01:31:16 by MACi
Strange, what version do you have?
Posted on 2003-06-12 06:55:33 by comrade

Thanks comrade, I included the macros, but:
flat assembler version 1.46
debug5.asm [133] pushd [19]:
showhex 'accumulator',eax
error: undefined symbol.

:(
Posted on 2003-06-12 11:38:15 by MACi
Try:
macro showhex caption,value {

local .over,.str
jmp .over
.str db caption," = %08Xh",0
.over: pushad
mov ebx,value
push GMEM_MOVEABLE+GMEM_ZEROINIT,1000h
call [GlobalAlloc]
push eax eax eax
call [GlobalLock]
push eax,eax,OFFSET .str,ebx
call [wsprintf]
add esp,12
pop eax
push 0,eax,0,MB_OK+MB_ICONASTERISK+MB_APPLMODAL
call [MessageBox]
call [GlobalUnlock]
call [GlobalFree]
popad
}
Posted on 2003-06-12 18:32:03 by comrade
with this:
flat assembler version 1.46
debug6.asm [46] showhex [6]:
showhex 'num',eax
error: invalid operand.

:(
Posted on 2003-06-13 02:33:18 by MACi

with this:
flat assembler version 1.46
debug6.asm [46] showhex [6]:
showhex 'num',eax
error: invalid operand.

:(

The error occurs at the push which really is a macro, since commrade is pushing two vars at the same time (I don't use that mpush/pop macro, so I don't know in what inclued it's defined).
Here's the pice of code without that macro (I think, I can't find the push/pop macro in any of my includes, commrade where is it defined?), you should be able to compile it:
macro showhex caption,value {

local .over,.str
jmp .over
.str db caption," = %08Xh",0
.over: pushad
mov ebx,value
push 1000h
push GMEM_MOVEABLE+GMEM_ZEROINIT
call [GlobalAlloc]
push eax
push eax
push eax
call [GlobalLock]
push ebx
lea eax, [.esi]
push esi
push eax
push eax
call [wsprintf]
add esp,12
pop eax
push MB_OK+MB_ICONASTERISK+MB_APPLMODAL
push 0
push eax
push 0
call [MessageBox]
call [GlobalUnlock]
call [GlobalFree]
popad
Posted on 2003-06-13 05:30:53 by scientica
thanks, but...
flat assembler version 1.46
debug6.asm [46] showhex [14]:
showhex 'num',eax
error: undefined symbol.

:(
Posted on 2003-06-16 03:04:43 by MACi
Aha, line 14 in the macro:
lea eax, [.esi]
this should be
lea eax,
(no dot before esi, my typo :o)

btw: Hot to 'decode' macro errors:
debug6.asm [46] showhex [14]:
in debug6.asm on line 46, the showhex macro is called and there is an error in line 14 of the macro
Posted on 2003-06-16 05:30:54 by scientica

btw: Hot to 'decode' macro errors:
debug6.asm [46] showhex [14]:
in debug6.asm on line 46, the showhex macro is called and there is an error in line 14 of the macro


I know that numbers mean rownumbers :) I just looked through the dot without sense :)

Anyway, thanks, it compiles now, the only matter is that the exe crashes.
Posted on 2003-06-16 05:40:41 by MACi