CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2005
    Location
    Ottawa, Ontario, Canada
    Posts
    82

    Angry Why is it locked?

    Hello,

    I have created a static C++ DLL and exported a function on it. The function creates a .gif file. I then interface the DLL in my C# project and I call the C++ function through C++.
    I view the .gif file that has been created in a pictureBox. When I clear the pictureBox and try to view the .gif, an NullPointerException is thrown!
    When I try to delete the .gif file manulaly, it says that another process is using the .gif file.
    I figured that MyC#Project.exe is the one locking my .gif

    Is there a way to be able to view .gif, clear them, and then view them again in the pictureBox?

    Help Gurus!!

    Ali

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Why is it locked?

    Sounds to me like the file handle is being kept open - i.e. whichever code you're using to write the .gif isn't closing the file handle after it's finished.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Nov 2004
    Posts
    37

    Re: Why is it locked?

    hi, how are you trying to create the gif file?

    any information you can give me on creating gif files would be off great use?

  4. #4
    Join Date
    Jun 2005
    Location
    Ottawa, Ontario, Canada
    Posts
    82

    Re: Why is it locked?

    Hi djing1985,

    I am using an open source library called GUIDO. There is a function to convert GUIDO music notation files (.gmn) to (.gif) files. You can use some functions in the library that are responsible of drawing the .gif file. I don't thik it is a "clean" way of getting what you want.

    Anyways, here is the link:
    http://sourceforge.net/projects/guidolib/

    It is in C++ by the way.
    Good Luck!
    Ali

  5. #5
    Join Date
    Nov 2004
    Posts
    37

    Re: Why is it locked?

    ok cool thanks, i think your right though prob not what i want.

  6. #6
    Join Date
    Jun 2005
    Location
    Ottawa, Ontario, Canada
    Posts
    82

    Re: Why is it locked?

    Hello Darwen,

    I finished checking all the fclose commands and everything is there! The .gif file is first drawn in the memory and then thrown into a file. Again, I am using an open source library, and here is how they draw the .gif - After it has been drawn in the memory- :

    Code:
    boolean GIF::WriteFile(const char* filename,GIF_FORMAT gf)
    {
    	if((output_file=fopen(filename, WRITE_BINARY)) == NULL) return FALSE;
    
    	HeaderWriteFile();
    	PixelsWriteFile();
    	FinishWriteFile();
    	fclose(output_file);
    
       if(gf==GIF89a)
       {
          rename(filename,"$tmpgif$.gif");
       	if(Gif87aToGif89a("$tmpgif$.gif",filename)) return FALSE;
       }
    
    	return TRUE;
    }
    As you see, it is properly closed!

    Other suggestions?

    Ali

  7. #7
    Join Date
    May 2002
    Posts
    511

    Re: Why is it locked?

    I had a different similar problem.

    My guess is that you are missing a Dispose() something in either your pictureBox code or in the display of the image.

  8. #8
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Why is it locked?

    I agree. If you're using a FileStream to open a stream for C# to read the gif image you have to close it afterwards.

    The nicest way of doing this is by the "using" keyword :

    See here :

    http://www.codeguru.com/Csharp/Cshar...cle.php/c8679/

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  9. #9
    Join Date
    Jun 2005
    Location
    Ottawa, Ontario, Canada
    Posts
    82

    Re: Why is it locked?

    Ait! Works now!

    Thanks guys!

    Ali

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured