Click to See Complete Forum and Search --> : Why is it locked?


khanafer
July 19th, 2005, 10:22 AM
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

darwen
July 19th, 2005, 10:48 AM
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.

djing1985
July 19th, 2005, 03:06 PM
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?

khanafer
July 19th, 2005, 04:53 PM
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

djing1985
July 20th, 2005, 04:15 AM
ok cool thanks, i think your right though prob not what i want.

khanafer
July 20th, 2005, 12:05 PM
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- :


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

Tron
July 20th, 2005, 04:22 PM
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.

darwen
July 20th, 2005, 06:22 PM
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/Csharp/cs_syntax/interfaces/article.php/c8679/

Darwen.

khanafer
July 21st, 2005, 01:20 PM
Ait! Works now!

Thanks guys!

Ali