The MASM Forum

General => The Campus => Topic started by: xandaz on November 18, 2020, 02:46:18 AM

Title: File creation error. File disappears after app close!!!
Post by: xandaz on November 18, 2020, 02:46:18 AM
    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
Title: Re: File creation error. File disappears after app close!!!
Post by: Vortex on November 18, 2020, 03:17:51 AM
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
Title: Re: File creation error. File disappears after app close!!!
Post by: nidud on November 18, 2020, 03:46:56 AM
deleted
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 18, 2020, 05:06:23 AM
   ok....it's not a binary value and cant be combinated. thanks
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 18, 2020, 05:19:28 AM
   Thanks Vortex but it didn'r work. File disappears after the app is closed. thanks anyway
Title: Re: File creation error. File disappears after app close!!!
Post by: Vortex on November 18, 2020, 06:12:39 AM
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?
Title: Re: File creation error. File disappears after app close!!!
Post by: jj2007 on November 18, 2020, 07:06:21 AM
Windows has a wonderful function called GetLastError. Strongly recommended!
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 18, 2020, 07:09:03 AM
    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.
Title: Re: File creation error. File disappears after app close!!!
Post by: HSE on November 18, 2020, 08:28:27 AM
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 ¿?
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 20, 2020, 05:41:38 AM
it keeps on. when i close the app the created files disappear. i need some help pls. thanks in advance
Title: Re: File creation error. File disappears after app close!!!
Post by: felipe on November 20, 2020, 07:49:08 AM
try not using the FILE_ATTRIBUTE_ARCHIVE flag  :icon_idea:
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 20, 2020, 08:19:37 AM
   i tried that. doesn't work either. all files created during the app run time disappear when app closes. thanks anyway
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 20, 2020, 08:24:42 AM
   no HSE.... the hProject handle gets freed at WM_DESTROY.
Title: Re: File creation error. File disappears after app close!!!
Post by: jj2007 on November 20, 2020, 08:42:12 AM
This can go on for weeks... unless you post complete code, of course.
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 20, 2020, 08:55:18 AM
   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.
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 20, 2020, 09:16:18 AM
   Good news. It wasn't a coding error. it was running under Avast Sandbox. That's why the files disappeared. ohhh....sorry for troubling you guys. You deserve better. sorry for inconviniance. Thanks posse   :thumbsup:
Title: Re: File creation error. File disappears after app close!!!
Post by: HSE on November 20, 2020, 10:31:42 AM
SandBox...  :hmmm:

You don't have so much faith in your programming skills :biggrin:
Title: Re: File creation error. File disappears after app close!!!
Post by: jj2007 on November 20, 2020, 12:11:10 PM
Glad you solved it :thumbsup:
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 20, 2020, 08:44:06 PM
    Thanks JJ. What do you mean exactely HSE. I put it there so the AV woudlnt nag me everytime i made a new build.
Title: Re: File creation error. File disappears after app close!!!
Post by: jj2007 on November 20, 2020, 09:38:41 PM
Quote from: xandaz on November 20, 2020, 08:44:06 PMI put it there so the AV woudlnt nag me everytime i made a new build.

Most if not all AV allow to exclude your \Masm32 folder (and all its subfolders) - a much better solution.
Title: Re: File creation error. File disappears after app close!!!
Post by: hutch-- on November 21, 2020, 01:43:07 AM
I would look for a better AV scanner, I personally use Kaspersky's KVRT.EXE which I download when I need it, run it then delete it. I absolutely don't want an AV scanner running all the time, if you have reasons to secure your computer for other people to use, set yourself up a separate profile that does not run the AV scanner all the time. On all of my boxes I have the default Microsoft AV running and it never caused me a problem.

While I was configuring one of the machines recently my catch it all "StartupMonitor" blocked something that was trying to install at startup so I used KVRT to fully remove it and it worked really well.
Title: Re: File creation error. File disappears after app close!!!
Post by: xandaz on November 21, 2020, 11:37:35 PM
   Yes. Thanks Hutch. Indeed Avast has an option to exclude a folder. Done that. Doing great.  :thumbsup: