Why does this code print this 1111* >111111111111111111111111111 and not 11111111<300>111111111111111111111111111 HELP

.model flat,stdcall
option casemap :none   ; case sensitive

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

main PROTO

lf    db "11111111<%d>111111111111111111111111111",10,13,0  
heap    HANDLE ?
hStdOut DWORD ?
;buffer DWORD ? ;this works



    invoke main
    invoke ExitProcess,0
   main proc
      LOCAL bs     :DWORD
      LOCAL bs2    :DWORD
      LOCAL buffer :DWORD ;this does not work 
      invoke GetStdHandle,STD_OUTPUT_HANDLE
      mov    hStdOut,eax

      invoke GetProcessHeap
      mov    heap, eax

      invoke HeapAlloc,heap,HEAP_ZERO_MEMORY,300
      mov buffer,eax
      .if buffer==NULL
         invoke ExitProcess,0
      invoke HeapSize,heap,0,buffer
      mov bs2,eax
      invoke wsprintf,addr buffer,addr lf,bs2
      mov bs2,eax
      invoke WriteFile,hStdOut,addr buffer,bs2,addr bs,NULL
      invoke Sleep,6000
   main endp   
end start
This message was edited by dan238, on 2/8/2001 6:30:56 PM
Posted on 2001-02-08 16:33:00 by dan238
The answer is right here. What you call "buffer" is not the buffer, but the pointer to the buffer. This is blatantly obvious because of the call to HeapAlloc. But you are telling wsprintf to store the resulting string in the pointer variable.

      invoke wsprintf,addr buffer,addr lf,bs2
Remove the addr that's before "buffer" here and in the WriteFile line.
Posted on 2001-02-08 22:59:00 by tank
Should have seen this thank you for the help.
Posted on 2001-02-09 01:27:00 by dan238