In my little delphi program, I use SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0) to get the length of the text in an edit windows. Then I use SendMessage(hEdit, WM_GETTEXT, txtLen, longint(aEditText)) to get all the text out and deal with these text.

It is easy in Delphi programming. But how can I code it in MASM? Because I do not know the length of the text before I fetch. How can I declare the variable?

How to handle such undefined length in MASM?

Thank you for your help.
Posted on 2003-05-26 04:16:35 by henryw
reallocate memory. That's how everything does it.

reallocate memory of the newer (bigger) size, copy the data over, free the previous block.

windows has many functions like global/localallock, heap(re)alloc etc...


hop to http://msdn.microsoft.com and check them out :)
Posted on 2003-05-26 05:01:07 by Hiroshimator
From win32.hlp:

The HeapReAlloc function reallocates a block of memory from a heap. This function enables you to resize a memory block and change other memory block properties. The allocated memory is not movable.




LPVOID HeapReAlloc(

HANDLE hHeap, // handle to a heap block
DWORD dwFlags, // heap reallocation flags
LPVOID lpMem, // pointer to the memory to reallocate
DWORD dwBytes // number of bytes to reallocate
);

Posted on 2003-05-27 04:56:13 by Vortex
Some books said that under DOS, memallocation is not always successful. Does this problem exist under windows?
Posted on 2003-05-27 07:30:01 by henryw
Memory reallocation is certainly not always successful if it's a non-movable block. But any memory allocation has a chance to fail under various circumstances. The most frequent being that there's no memory left to allocate. Virtual memory helps to get around this, but then you're limited by disk space.

You should always check for errors when you allocate memory.
Posted on 2003-05-27 09:23:02 by iblis
You could just use the stack for this, to avoid calling memory allocation functions.

Example:
invoke SendMessage,hEdit,WM_GETTEXTLENGTH,0,0
stc
push ebp
mov ebp,esp
sbb esp,eax
mov edx,esp
invoke SendMessage,hEdit,WM_GETTEXT,edx,eax
; process the text
leave
Posted on 2003-05-28 12:58:39 by Sephiroth3