Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Delete a File

Delete a File

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsgame-devhelpquestionlearning
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RahulOP
    wrote on last edited by
    #1

    I've created a Dialog based application that records audio(using DirectX of course) and changes the header of the audio file so that I get a file that is not playable by a regular player. Now,within my application itself,when I want to playback the said file,I decode the file to a "temp" with no extension and play it back. However I cant seem to delete the file either when I exit the application or when it finishes playing. I believe my application isnt letting go of the file when it finishes playing it despite the fact that I set all the DirectX interfaces to NULL(I tried to delete the file manually after it finished playing and got an "Access Denied" error) Any suggestions anybody?? Thank You

    R G 2 Replies Last reply
    0
    • R RahulOP

      I've created a Dialog based application that records audio(using DirectX of course) and changes the header of the audio file so that I get a file that is not playable by a regular player. Now,within my application itself,when I want to playback the said file,I decode the file to a "temp" with no extension and play it back. However I cant seem to delete the file either when I exit the application or when it finishes playing. I believe my application isnt letting go of the file when it finishes playing it despite the fact that I set all the DirectX interfaces to NULL(I tried to delete the file manually after it finished playing and got an "Access Denied" error) Any suggestions anybody?? Thank You

      R Offline
      R Offline
      Rinu_Raj
      wrote on last edited by
      #2

      Try calling DeleteFile(..) in your class's destructor Rinu Raj

      R 1 Reply Last reply
      0
      • R Rinu_Raj

        Try calling DeleteFile(..) in your class's destructor Rinu Raj

        R Offline
        R Offline
        RahulOP
        wrote on last edited by
        #3

        I'd try that IF i was exiting the application. But if I'm fooling around by recording and then repeatedly playing back,I'd like to be able to delete the file each time it finishes playing. Thanks for your suggestion though.Really appreciate it:)

        R 1 Reply Last reply
        0
        • R RahulOP

          I'd try that IF i was exiting the application. But if I'm fooling around by recording and then repeatedly playing back,I'd like to be able to delete the file each time it finishes playing. Thanks for your suggestion though.Really appreciate it:)

          R Offline
          R Offline
          Rinu_Raj
          wrote on last edited by
          #4

          You are creating a temp file right ? Close the file handle of the temp file then try DeleteFile(..) it will work Rinu Raj Rinu Raj

          R 1 Reply Last reply
          0
          • R Rinu_Raj

            You are creating a temp file right ? Close the file handle of the temp file then try DeleteFile(..) it will work Rinu Raj Rinu Raj

            R Offline
            R Offline
            RahulOP
            wrote on last edited by
            #5

            Umm, I tried that too but it doesnt work. What I am doing is using pGraph->RenderFile(abc,NULL);

            R 1 Reply Last reply
            0
            • R RahulOP

              Umm, I tried that too but it doesnt work. What I am doing is using pGraph->RenderFile(abc,NULL);

              R Offline
              R Offline
              Rinu_Raj
              wrote on last edited by
              #6

              will you paste the code you closing the handle of hile and removing file Rinu Raj

              R 1 Reply Last reply
              0
              • R Rinu_Raj

                will you paste the code you closing the handle of hile and removing file Rinu Raj

                R Offline
                R Offline
                RahulOP
                wrote on last edited by
                #7

                HRESULT res; IMediaControl *pMediaControl; IMediaEventEx *pEvent; if(pGraph==NULL) { CMainDlg *parent=(CMainDlg *)AfxGetApp()->GetMainWnd(); //CoInitialize(NULL); HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); if(hr==S_OK) { pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); pGraph->QueryInterface(IID_IMediaEventEx, (void **)&pEvent); // pEvent->SetNotifyWindow ((OAHWND)hwnd,WM_PLAYER_ENDOFMEDIA,NULL); USES_CONVERSION; //temp=parent->m_strAppPath+"\\home\\"+parent->m_strUserName+"\\videofiles\\"+GetFileName(""); if(DecodeMediaHeaderWithCopy(fileName,"temp")) { res=pGraph->RenderFile(A2W("temp"), NULL); pGraph->QueryInterface(IID_IMediaSeeking,(void **)&g_pSeek); } else res=pGraph->RenderFile(A2W(fileName), NULL); //res=pGraph->RenderFile(A2W(fileName),NULL); if(res!=S_OK) { pMediaControl->Release (); pEvent->Release(); return FALSE; } pMediaControl->Run (); pMediaControl->Release (); pEvent->Release(); if(FileExists("C:\\Executable\\dxh263\\temp")) { CFile m_File; if(!m_File.Open("C:\\Executable\\dxh263\\temp",CFile::modeRead,NULL)) AfxMessageBox("notexs"); //m_File.SeekToEnd(); m_File.Close(); } } else return FALSE; } return TRUE; } void CMPlayer::StopPlay () { IMediaControl *pMediaControl; IMediaEventEx *pEvent; if(pGraph==NULL) return; else { pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); pMediaControl->Stop (); pMediaControl->Release (); pGraph->QueryInterface(IID_IMediaEventEx, (void **)&pEvent); pEvent->SetNotifyWindow ((OAHWND)NULL,WM_PLAYER_ENDOFMEDIA,NULL); pEvent->Release (); pGraph->Abort(); pGraph->Release (); pGraph=NULL; pMediaControl=NULL; pEvent=NULL; } ::DeleteFile("C:\\Executable\\dxh263\\temp"); }

                1 Reply Last reply
                0
                • R RahulOP

                  I've created a Dialog based application that records audio(using DirectX of course) and changes the header of the audio file so that I get a file that is not playable by a regular player. Now,within my application itself,when I want to playback the said file,I decode the file to a "temp" with no extension and play it back. However I cant seem to delete the file either when I exit the application or when it finishes playing. I believe my application isnt letting go of the file when it finishes playing it despite the fact that I set all the DirectX interfaces to NULL(I tried to delete the file manually after it finished playing and got an "Access Denied" error) Any suggestions anybody?? Thank You

                  G Offline
                  G Offline
                  GudduRanchi
                  wrote on last edited by
                  #8

                  I think the file you have opened didnot get closed so First close the file using CloseHandle or fclose.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups