The MASM Forum

General => The Campus => Topic started by: xandaz on April 10, 2022, 05:03:36 AM

Title: Problems with WriteFile or whatever! Help Needed!
Post by: xandaz on April 10, 2022, 05:03:36 AM
    I have the following routine in the WndProc:       .elseif ax==IDM_SAVE
invoke RtlZeroMemory,addr ProjectFileBuffer,sizeof ProjectFileBuffer
            .if ProjectFlag==FALSE
                invoke  MessageBox,hWnd,addr szNoProjectOpened,addr szAttention,MB_OK
            .else
  mov ecx,noMdiChild
  or ecx,ecx
  jz _end
                push    hInstance
                pop     gofn.hInstance
                push    hWnd
                pop     gofn.hWndOwner
mov   gofn.lStructSize,sizeof gofn
                mov     gofn.lpstrFilter,offset ProjectFilter
                mov     gofn.lpstrTitle,offset szSaveProject
                mov     gofn.lpstrFileTitle,offset szFileBuffer
                mov     gofn.lpstrFile,offset szProjectBuffer
  mov gofn.lpstrDefExt,offset ProjectExt
                invoke  GetSaveFileName,addr gofn
                or      eax,eax
                jz      end_save
                invoke  SetWindowText,hWnd,gofn.lpstrFileTitle
                invoke  CreateFile,gofn.lpstrFile,GENERIC_WRITE,\
                            FILE_SHARE_WRITE,0,CREATE_ALWAYS,\
                            FILE_ATTRIBUTE_NORMAL or FILE_FLAG_WRITE_THROUGH,0
                mov     hProject,eax
         invoke SaveFiles
               invoke  BuildProjectFile,hWnd
               invoke  CountBytes2,addr ProjectFileBuffer
                invoke  WriteFile,hProject,addr ProjectFileBuffer,ecx,\
                                  addr noBytesWritten,0
                invoke CloseHandle,hProject
           .endif

    It's suppose to record a project file with MDI chikd windows. It works the first time i execute it. If i make any changes link closing one of  the child  windows it crashes. is it possible to grasp what the error is with this few information?
Title: Re: Problems with WriteFile or whatever! Help Needed!
Post by: jj2007 on April 10, 2022, 06:05:34 AM
Quote from: xandaz on April 10, 2022, 05:03:36 AMis it possible to grasp what the error is with this few information?

Absolutely! GetLastError is your friend.
Title: Re: Problems with WriteFile or whatever! Help Needed!
Post by: HSE on April 10, 2022, 06:46:34 AM
Can you see content of ProyectFileBuffer?
Title: Re: Problems with WriteFile or whatever! Help Needed!
Post by: xandaz on April 10, 2022, 02:46:57 PM
   Yes I can. The problem is in the child windows array. when i close a child window the handle is no lonmger valid, hence the error. thanks guys.