News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

dialog box and memory

Started by ToutEnMasm, June 20, 2006, 06:25:15 AM

Previous topic - Next topic

ToutEnMasm

Hello,
I search informations on how the dialog box use memory and don't find it.
The problem is:
When allocating memory with globalalloc in the main window, the pointer couldn't be passed to the dialog box.
When allocating memory with globalalloc in the dialog box ,the pointer is good but sometimes,there is a problem when deallocating it,the pointer can ba passed to the main window.
Is there some informations on the subject somewhere ?.
                                ToutEnMasm


hutch--

Correct me if I am wrong but it sounds like a scope issue. Any memory allocation strategy from Windows is not contained by the scope of a procedure but the pointer that stores its address can be lost if it is declared within local scope and the procedure closes destroying the pointer. If this is the case, you need a pointer variable of GLOBAL scope so you don't have these problems.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ToutEnMasm


A little example;

I am in the main window (createwindowex),i allocate memory in this window (globalalloc and then globallock for a pointer ,memory movable).This window call a dialog box and the dialog box want to read the memory,The dialog box found the data where is the pointer,try to read the memory and it's wrong at each time.
What can I do to correct this ?
Recall globallock with the handle of memory and have a new pointer ?
I don't understand very much "Global Scope" and what actions to do with it.
                                  ToutEnMasm

                                   

mnemonic

Global Variables may be created e.g. in the .data section:
.data
gVar dd 0

You can safely access/set the contents of gVar everywhere in your program.

Local variables are for example:
myProc proc pVar:DWORD
LOCAL lVar:DWORD
myProc endp

pVar and lVar are only valid inside myProc and in procs that are called within myProc if you access them in the called procs by the address they have on the stack.
Local variables always reside on the stack.
If myProc returns, lVar and pVar do not exist any longer.

Regards
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

ToutEnMasm


I understand this,so the dialog load the pointer in the global data,it's the good pointer (he works in the main windows) but in the dialog box ,with the same value ,it's bad.
Try it.
                                  ToutEnMasm

hutch--

One thing, if you are going to use the old GlobalAlloc(), use it with the GMEM_FIXED flag as the other styles are no longer useful. You just use the return value as the pointer to the allocated memory and don't have to lock it as you do with the other styles. Make sure like normal that you use GlobalFree() when you no longer need it.

If it is a problem with some weird memory clash when using a dialog box, post the code or at least some of it so we can have a look at it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ToutEnMasm


Well,I made a little sample to see if it work and ... it work.
The source is a little too big and i find that something trouble the memory.
Windbg as new features to see if the memory is written out of the limits.
Finally it's a good test to see if the memory is wealthy
                                       Thanks for answers