tags:

views:

529

answers:

3

Hi all,

I have a third-party component that copy an image and opens it for a certain task, but it seems that it's no releasing the file handle.

I've read the documentation of that component, but it was released like in 2004 and there's a certain method to release the handle, but of course it needs an (int bmpPtr). so it's obviously a pointer. So the question is: Is there a way to retrieve the open handles on a certain file ... And in case somebody knows, is there a way to know what's the identity of the opening process?

And the problem is in C# not in C++ . I would prefere a solution without DLLImport, but i don't think it's doable. Cheers

+1  A: 

Closing the file handle out from underneath the component is probably not the best idea, and I don't know that it can be done from C#. However, you should look for a Dispose method on the component you are using. Typically, Dispose is used to clean up unmanaged resources, such as file handles.

heavyd
Alternatively think of the `using () {}` idiom, that will save you nerves in case of exceptions.
jdehaan
A: 

If it has a method that needs bmpPtr, then there was a method that returned a bmpPtr. Find out which one, where you called it, save the bmpPtr then use it later to release.

John Saunders
yeah exactly, but it didn't .I'm using a certain "CimgCopyCurrentRegion" that return an 'OLE_HANDLE' according to the documentation. But in VS it says it's an int (and it's not the pointer since it's returning the value '1').now this same procedure is the one copying the image, and persisting it, and leaving the handle open. Now i'm ran through all the methods, there was none that could free the handle. or get the handle. It's seemingly an old component, so they didn't take into consideration all that.anyway that's my case, and i want to get the handle manually and kill it.
+1  A: 

I'm not sure if this applies, but just for the record: if you load a bitmap with Image.FromFile, the file will be open until the image is disposed.

danbystrom