Why does this code print this 1111* >111111111111111111111111111 and not 11111111<300>111111111111111111111111111 HELP
This message was edited by dan238, on 2/8/2001 6:30:56 PM
.386 .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 .data lf db "11111111<%d>111111111111111111111111111",10,13,0 .data? heap HANDLE ? hStdOut DWORD ? ;buffer DWORD ? ;this works .code start: 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 .endif 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 ret main endp end start
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.
Remove the addr that's before "buffer" here and in the WriteFile line.
invoke wsprintf,addr buffer,addr lf,bs2
Should have seen this thank you for the help.