I will repost a resolution from a previous thread, I think it is MrGone's..

see below for:
.data?

Pntbuffer db 8192 dup(?)

How can it be printed to when it is not initialized.. or is that not how masm pointers work? Or is wsprintf setting the pointer of Pntbuffer to the displayPnt ??




.data

pt dd 0
x dd 0
y dd 0
hexptx dd 0
hexpty dd 0

displayPnt db "X coordinate: %08x",0Dh,0Ah
db "Y coordinate: %08x",0Dh,0Ah
CODE1 db "Caret Parameters:",0


.data?

Pntbuffer db 8192 dup(?)


position:
test shiftKey,10h
jz DoNothing
invoke GetCaretPos,addr pt
mov eax,x ; pt=y "pt or x"
mov hexptx,eax
mov eax,pt
mov hexpty,eax
invoke wsprintf,addr Pntbuffer,addr displayPnt,hexptx,hexpty invokeMessageBox,hEdit,addrPntbuffer,addrCODE1,MB_
OK+MB_ICONINFORMATION
xor eax,eax
mov shiftKey,eax
invoke SetFocus,hEdit
Posted on 2003-12-17 10:03:13 by drarem
Or is wsprintf setting the pointer of Pntbuffer to the displayPnt ??

Right about that.

The wsprintf function formats and stores a series of characters and values in a buffer. Any arguments are converted and copied to the output buffer according to the corresponding format specification in the format string. The function appends a terminating null character to the characters it writes, but the return value does not include the terminating null character in its character count.

int wsprintf(

LPTSTR lpOut, // pointer to buffer for output
LPCTSTR lpFmt, // pointer to format-control string
... // optional arguments
);



Also the maximum output buffer size of wsprintf is 1024. No use setting it to be more than that, you are just wasting the time needed to assemble the program.
Posted on 2003-12-17 10:06:15 by roticv
drarem,

I find your posting ... confusing.
I will repost a resolution from a previous thread, I think it is MrGone's..

What is the resolution? What is the problem? Where is the link to the previous thread? You appear to be asking questions below.
How can it be printed to when it is not initialized..

It can be submitted for printing, but the output will be nothing or garbage.
or is that not how masm pointers work?

How are they not working the way you think they are?
Or is wsprintf setting the pointer of Pntbuffer to the displayPnt ??

No, the programmer sets the pointer.

Have you tried to assemble the code you enclosed? That which you have instructions in the .DATA? section? And two CALLs on one line?

What is the problem and what is the resolution? Ratch
Posted on 2003-12-17 15:27:21 by Ratch
since when did forum questions require dissertations?

Instead of hijacking a thread, I posted a new one from an example posted earlier on here. I forget where the link was, but if you were here earlier today lurking you would have come across it. The actual questions are followed by a question mark. I was referring to:

Pntbuffer db 8192 dup(?)

which I guess I didn't make clear enough.

Trying to 'print' (write) to a non-initialized pointer can cause a memory-write error followed by a crash or as you have stated, if you're lucky, garbage/nothing will be stored and trying to print that location to the screen would result in garbage or nothing. Reading of course would cause a memory-read error.

The programmer doesn't set the pointer, he writes the code.. the compiler/linker sets the pointers. Yes I tried the example and it worked fine, I was slightly curious.

BTW ty Roticv, you satisfied my curiosity without killing the cat 'yet'..
Posted on 2003-12-17 16:51:26 by drarem

I will repost a resolution from a previous thread, I think it is MrGone's..

see below for:
.data?

Pntbuffer db 8192 dup(?)

How can it be printed to when it is not initialized.. or is that not how masm pointers work? Or is wsprintf setting the pointer of Pntbuffer to the displayPnt ??



Pntbuffer is not a pointer it is an array. If you want a pointer to something you would define it as "Pntbuffer dd ?".
Posted on 2003-12-18 13:50:04 by Beelzebub

Pntbuffer is not a pointer it is an array. If you want a pointer to something you would define it as "Pntbuffer dd ?".


alright then, I'm confused.

.data?
buffer1 dd 80 DUP(?)
buffer2 dd DUP(?)


buffer1 is not a pointer to the array as you say? Is it defined in runtime then?

buffer2 is a pointer, and I guess I could do a heapalloc to create a dd array of buffer2's? What is the difference between the two?
Posted on 2003-12-20 10:01:05 by drarem
... getting back to the initial question

How can it be printed to when it is not initialized.. or is that not how masm pointers work? Or is wsprintf setting the pointer of Pntbuffer to the displayPnt ??

.data?

Pntbuffer db 8192 dup(?)

Pntbuffer is an 8192 byte block of uninitialised data (which wont be present in the exe, primarially the reason people use uninitialised data is that the exe wont be filled
with a block of zeroes in the data segment, which would bloat the exe size, say for example you had a 1mb memory buffer in your program, you'd find you'd have a nice block 1mb in size of all zeroes and exe would be 1mb+size of code, however puting the buffer as uninitialised data will reduce the size of the exe because the buffer isnt present in the compiled exe (but will be when the image is loaded)

in the wsprintfa case, the call will take the parameters and 'build' it into the Pntbuffer memory area, debug it using softice, you'll see it a lot clearer then
Posted on 2003-12-20 11:19:07 by evlncrn8
drarem,
Offset buffer1 certainly could be considered a pointer to a 80 char array/buffer. The storage is not allocated until the program is loaded. Then the contents are defined by the program during run time by writing into it. Your code syntax for buffer2 should be buffer2 dd ? . If your program writes a buffer address into the contents of buffer2, then that surely is a buffer pointer. Are we getting hung up on semantics? A buffer pointer is simply a address that references the beginning of a designated data area called a 'buffer' or 'array'. It all looks the same in a dump. Ratch
Posted on 2003-12-20 11:32:31 by Ratch