News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Problems with WriteFile or whatever! Help Needed!

Started by xandaz, April 10, 2022, 05:03:36 AM

Previous topic - Next topic

xandaz

    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?

jj2007

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.

HSE

Equations in Assembly: SmplMath

xandaz

   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.