News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

File creation error. File disappears after app close!!!

Started by xandaz, November 18, 2020, 02:46:18 AM

Previous topic - Next topic

xandaz

    I have this code:
.elseif ax==IDM_SAVE
       
            push    hInstance
            pop     gofn.hInstance
            push    hMainWindow
            pop     gofn.hWndOwner
            mov     gofn.lpstrFilter,offset ProjectFilter
            mov     gofn.lpstrTitle,offset szSaveProject
            invoke  GetSaveFileName,addr gofn
            or      eax,eax
            jz      end_save
            invoke  SetWindowText,hWnd,gofn.lpstrFileTitle
            invoke  CreateFile,gofn.lpstrFile,GENERIC_READ+GENERIC_WRITE,\
                        FILE_SHARE_READ+FILE_SHARE_WRITE,0,CREATE_NEW+\
                        OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE+FILE_ATTRIBUTE_NORMAL,\
                        0
             mov     hProject,eax
             invoke  BuildProjectFile,hWnd
             invoke  CountBytes,addr ProjectFileBuffer                                   
             invoke  WriteFile,hProject,addr ProjectFileBuffer,ecx,\
                        addr noBytesWritten,0
             invoke  CloseHandle,hProject


    When i go back to load the file it isnt there... what is it? any ideas. Thanks in advance

Vortex

Hello,

Try to simplify your CreateFile parameters. Here is how I use it :

    xor     ebx,ebx
    invoke  CreateFile,pFileName,GENERIC_WRITE,\
            ebx,ebx,CREATE_ALWAYS,ebx,ebx

nidud

deleted

xandaz

   ok....it's not a binary value and cant be combinated. thanks

xandaz

   Thanks Vortex but it didn'r work. File disappears after the app is closed. thanks anyway

Vortex

Hi xandaz,

             invoke  WriteFile,hProject,addr ProjectFileBuffer,ecx,\
                        addr noBytesWritten,0


BOOL WriteFile(
  HANDLE       hFile,
  LPCVOID      lpBuffer,
  DWORD        nNumberOfBytesToWrite,
  LPDWORD      lpNumberOfBytesWritten,
  LPOVERLAPPED lpOverlapped
);


nNumberOfBytesToWrite is ecx in your case but what happened to this register?

jj2007

Windows has a wonderful function called GetLastError. Strongly recommended!

xandaz

    Vortex. the bytes have been counted by a procedure and result is in ecx. It works. I open the file and there's the data just the way it should be. It's when i close the app that file disappears. Thanks a lot.

HSE

Hi xandaz!

Here application crash when closing, the file remain perfectly.



    .if     uMsg==WM_DESTROY
quit:   
        invoke  CloseHandle,hProject

In theory this hProject is alredy closed ¿?
Equations in Assembly: SmplMath

xandaz

it keeps on. when i close the app the created files disappear. i need some help pls. thanks in advance

felipe


xandaz

   i tried that. doesn't work either. all files created during the app run time disappear when app closes. thanks anyway

xandaz

   no HSE.... the hProject handle gets freed at WM_DESTROY.

jj2007

This can go on for weeks... unless you post complete code, of course.

xandaz

   you said it yourself.... i need a new approach to coding JJ. I have here a mix of Unicode and ANSI proceedings that are killing me.