The MASM Forum

General => The Campus => Topic started by: xandaz on November 19, 2020, 08:48:19 AM

Title: Problems closing handles give error o memory access....HELP
Post by: xandaz on November 19, 2020, 08:48:19 AM
    i have this code for app termination. it should close the handles of the files associated with their respective windows...
close_handles:   
        cmp     noMdiChild,0
        je      done_close_handles
        invoke  SendMessage,hMdi,WM_MDIGETACTIVE,0,0
        mov     hCurrentWindow,eax
        invoke  GetWindowLong,eax,GWL_USERDATA
        invoke  CloseHandle,[eax.MdiStruct.hFile]
        invoke  SendMessage,hWnd,WM_MDIDESTROY,hCurrentWindow,0
        dec     noMdiChild
        jmp     close_handles   


When i close the app it gives an error on memory access that is not for reading. can someone help me out?
Title: Re: Problems closing handles give error o memory access....HELP
Post by: xandaz on November 19, 2020, 09:17:53 AM
   I''m using SendMessage,hMdiClient,WM_USER+100,0,0 But the mdiproc doesnt recieve the message. Why the hell would that be?
Title: Re: Problems closing handles give error o memory access....HELP
Post by: xandaz on November 19, 2020, 09:44:57 AM
   Well...i guess the problem is how to send messages to mdi child proc.
Title: Re: Problems closing handles give error o memory access....HELP
Post by: zedd151 on November 19, 2020, 12:23:43 PM
Could we see a little more code?

You could try to use a message box to see if the said handles actually exist, for debugging..

invoke MessageBox, 0, hex$(handle), 0, 0

where handle is the suspect handle

;;;;;;;;;;;;

Or run it in a debugger and see better what is going on with the code while stepping the code.

Title: Re: Problems closing handles give error o memory access....HELP
Post by: jj2007 on November 19, 2020, 01:41:41 PM
Quote from: zedd151 on November 19, 2020, 12:23:43 PM
Could we see a little more code?

Why, is your crystal ball not working?
Title: Re: Problems closing handles give error o memory access....HELP
Post by: daydreamer on November 19, 2020, 06:24:57 PM
Quote from: xandaz on November 19, 2020, 09:44:57 AM
   Well...i guess the problem is how to send messages to mdi child proc.
look at Hutch example for send messages between two programs,maybe you need too register custom messages to make them work?
I think you should add some error checking code,checking for return eax==NULL and use a messagebox,because later down in the code NULL pointer gives you that error on memory access
sometimes its just forget to addr filename,instead of just filename in invoke
@JJ
crystall ball sounds like a great name for a debugger :biggrin:
Title: Re: Problems closing handles give error o memory access....HELP
Post by: xandaz on November 19, 2020, 07:46:10 PM
    Thanks guys. I've tried also PostMessage and MdiProc doesn't recieve the message....
Title: Re: Problems closing handles give error o memory access....HELP
Post by: xandaz on November 19, 2020, 09:15:29 PM
   did something stupid. I subclassed the MDIClient window and call both CallWindowProc and DefMdiChildProc. It accepts the message