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.
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.
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 :)
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 :)
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.
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
);
Some books said that under DOS, memallocation is not always successful. Does this problem exist under windows?
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.
You should always check for errors when you allocate memory.
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
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