Is there any way of changing the string to be displayed in a message box, I have put a few message boxes temporarily into my program to check some results whilst it is running, but when I try to insert (ascii) numbers into the string the results are very unpredictable at least. At the moment I've had to resort to using TextOut. Numbers can be inserted into the string and display correctly, why won't the message boxes:confused:
Mel
Posted on 2001-08-27 12:28:28 by Mel
Mel,

Use wsprintf:

LOCAL szMsg[100]:BYTE
szText szFormat, "My Number is: %i"
wsprintf addr szMsg, addr szFormat, iMyNumber
invoke MessageBox, 0, addr szMsg, 0, 0

Xtreme
Posted on 2001-08-27 12:54:23 by Xtreme
Maybe you're over writing the NULL byte at the end.

Since you specify the number of characters with TextOUt that wouldn't be a problem there, but message boxs require null terminated strings
Posted on 2001-08-27 12:57:24 by Eóin
Thanks Extreme, I'll use your way in future but I'm still a little puzzled why I can't insert characters into a message box string:confused:
I'm not overwriting the null at the end, I'm inserting the (4) characters into the middle of the string Where space has been left for them,
Mel
Posted on 2001-08-27 13:39:43 by Mel
Are we to assume you're changing the string BEFORE you call MessageBox ?
Posted on 2001-08-27 14:49:55 by tank
The obvious trouble shooting:
Make sure you are passing the right params to the box, it takes DWORD pointers to the start of the string in memory not the string as a DWORD.

In this example the string doesn't change the pointer does preventing you from the extreme hasle of shifing bits one by one.



; Messege boxes (eax return):
; type 1:
; 1 = okay
; type 2
; 6 = yes
; 7 = no

.586
.model flat,STDCALL
extrn MessageBoxA:PROC
extrn ExitProcess : PROC

.data
chose db "Chose:",0
c db "What",0
d db "Choose Somthing",0
yes db "The answer was no fool",0
no db "Don't talk back!",0
.data?
T DWORD ?
.code
start:

thing:
push 4
push offset [c]
push offset [d]
push 0
call MessageBoxA
jmp get

box:
push 0
push offset[chose]
push T
push 0
call MessageBoxA
jmp thing

call ExitProcess

get:
.IF (eax == 6)
push offset[yes]
.ELSE
push offset[no]
.ENDIF
pop T
jmp box
end start
Posted on 2001-08-27 17:40:10 by -T-
I know someones going to rip me apart for that code, I have fixed it for you cynics. That was first ASM program ever I tried to hit a few ASM birds with one stone with it.

Here is better code, hoever will not help you in your quest to changing the messege box:



.386
.model flat,STDCALL
extrn MessageBoxA:PROC
extrn ExitProcess : PROC

.data
chose db "Chose:",0
c db "What",0
d db "Choose Somthing",0
yes db "The answer was no fool",0
no db "Don't talk back!",0

.data?
.code
start:
xor ebx, ebx
call MessageBoxA, ebx, offset [d], offset [c], 4

push ebx
push offset[chose]
.IF (eax == 6)
push offset[yes]
.ELSE
push offset[no]
.ENDIF
push ebx
call MessageBoxA

jmp start

call ExitProcess
end start

:stupid:
Posted on 2001-08-27 17:51:44 by -T-
Mel post your source (or attach it). Im curious myself. You say your converting a register value into ASCII one number (power of 10) at a time and then writing this byte into a specific text string???

If so, my money is on:

1) How you convert from binary to Ascii chars (3xH's)

or

2) when you mov the ascii char to the string, you may have address-of ('[' and ']' s) brackets around the actual 3xH value. In this case, mem byte located at 0000003xH is copied into your string.. (which would look like gibberish).

Long story short, you CAN have the message box display numbers in its string..

Alternatively tho, I strongly recomend getting Ernie's DMacros.inc set from his web page Here .

I use them alllllll the time they quick and ez, and designed such you dont 'have' to clean up behind you if you dont want to in your final release, as there is an equate to control their insertion or not. (in the final code)

Anywho, keep at it!
:alright:
NaN
Posted on 2001-08-27 22:33:14 by NaN
Hi NaN,
here is my basic code, sorry it's not all commented

.data
thous db 32
huns db 32
tens db 32
units db 32

myMsg db"The result is times",0
;there are 6 spaces between is & times that are in my original code but go missing when I post it up here


.code

bintoasc: ;binary to ascii conversion
push eax

invoke FillBuffer,ADDR thous,4,32 ;space used to blank out leading zeros

pop eax
lea edi,units
mov cx,10


@@:
cmp ax,10
jb @f
xor dx,dx
div cx
add dl,48
mov ,dl
dec edi
or ax,ax
jnz @b
ret
@@:
add al,48
mov ,al
ret

;Message box routine

lea edi,myMsg+14
lea esi,thous
mov ecx,4
rep movsb

invoke MessageBox,hWnd,ADDR myMsg,ADDR szDisplayName,MB_OK

Mel
Posted on 2001-08-28 01:45:52 by Mel
Mel,
;there are 6 spaces between is & times that are in my original code but go missing when I post it up here


You can get around this by using the [ code ] and [ / code ] switches (no spaces tho).

As for your problem.. It works fine! (with one fix that must of accidently fixed your problem). I dont know where 'FillBuffer' came from, but since i dont have it, i just commented it out and provided a better solution:
   lea edi, thous

mov dword ptr [edi], 20202020h ; 4 spaces


Once i ran this, it worked every time... So im willing to bet your problem is in the FillBuffer call...

Here is my source:
DEBUGC equ 1

.586
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\dmacros.inc
include \masm32\include\_macros_.inc
include \masm32\include\kernel32.inc
include \masm32\include\_macros_.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib


.data
thous db 32
huns db 32
tens db 32
units db 32

myMsg db "The result is times",0
;there are 6 spaces between is & times that are in my
;original code but go missing when I post it up here
szDisplayName db "NaN was Here.."


.data?
.code
start:
push ecx
push esi
push edi

; --==========================================
; This is the Number to be converted...
; --==========================================
mov eax, 1000h

bintoasc: ;binary to ascii conversion

;push eax
;invoke FillBuffer,ADDR thous,4,32 ;space used to blank out leading zeros
;pop eax

lea edi, thous
mov dword ptr [edi], 20202020h ; 4 spaces

lea edi,units
mov cx,10


@@: ; ax has source bin val
cmp ax,10 ; if less than 10 leave
jb @f
xor dx,dx ; edx == 0, ax >= 10
div cx ; ax/10 == ax + dx remainding
add dl,48 ; dl now is in 3xh for string
mov [edi],dl ; stored in Units.
dec edi ; move to Tens.. etc. etc.
or ax,ax ; (( ax will never be zero ))
jnz @b ; jmp back..
ret
@@: ; leave..
add al,48 ; add 48 + (0 -> 9) == 30h -> 39h
mov [edi],al ; save al to addr in edi
;ret ; exit (rem'd so i can goto the message box)

;Message box routine

lea edi,myMsg+14
lea esi,thous
mov ecx,4
rep movsb

; NULL'd hWnd, this is ok... just no parent window
invoke MessageBox,NULL,ADDR myMsg,ADDR szDisplayName,MB_OK

pop edi
pop esi
pop ecx
call ExitProcess
end start


Anywho.. I hope this helps..
:alright:
NaN
Posted on 2001-08-28 13:23:03 by NaN
I assembled my code again and I was totally amazed when this time it worked, I tried most of Sunday to get it going before. After a lot of investigation and the strange results I was getting I can only assume that the original code (now deleted) was something like this
lea edi,

You were probably right NaN, now please excuse me whilst I go and bang my head against the wall a few times,
Mel:mad:

Thanks for your code NaN, the FillBuffer proc appeared in my program when I used Hutches Prostart, I think?
Posted on 2001-08-28 13:23:16 by Mel