I'm using Win7-64-bit, Visual Studio 2010 Pro, and Matlab R2010b. I'm generating 32-bit code for everything and have written a C DLL that contains a function that creates a Matlab .mat file using the MATFile API functions. I use this DLL in a C# program. It creates the desired .mat file perfectly and the contents and readability by Matlab are also perfect. At the end of the creation process I call matClose to close the file and test its return value to make sure matClose was successful, and it does return a 0. However, after the DLL function returns to my C# code and it try to delete the .mat file that was just created, an exception is thrown that says that the file cannot be deleted because it is being accessed by another process. To test this another way I placed a breakpoint in my code just after the DLL function return and when the program paused I went to Windows Explorer and tried to delete the file manually, but I got the same error about the file still being in use. Once I kill my entire application I can delete the file. I'm afraid that if I can't resolve this in a simple way my next step will probably be to try to unload then reload the entire DLL itself but I don't want to have do that because from what I've seen it's a real mess, plus I'm not sure that would solve the problem anyway. I would have actually preferred to use the CSMatIO .NET component rather than kluging together this C DLL, but I could never get it to work. Although it would seem to create a .mat file okay, Matlab couldn't read it.