Hi All,
wonder if someone can point out what I am doing wrong.....I am creating
memory mapped files on win2000 using CreateFile and CreateFileMapping
and MapViewOfFile. At the end of the program I figured it would be
nice to clean up these files but when I issued the del <filename> as a
system command (or if I try the DeleteFile function) I get a message
saying that the file is in use by another process.....Is there
something else I must do to release a file that I have set up using
CreateFile and CreateFileMapping and MapViewOfFile???

Any tips greatly appreciated...




//////////////////////////////////////////////////////////////////////////////////////////////
// When the job ends deleted the wait file, the kill file, and any
memory mapped files that //
// have been created by this process.
//
//////////////////////////////////////////////////////////////////////////////////////////////
ptr_WaitFile->Delete() ;
ptr_KillFile->Delete() ;
for (index1 = 0 ; index1 < ws_used_memory_mapped_files ; index1++)
BEGIN_

#if defined (_MSC_VER)
UnmapViewOfFile(ptr_MemMapBuffer_array[index1]) ;
DWORD dw1 = GetLastError();
CloseHandle(ws_HandleForMemMapFile_array[index1]) ;
DWORD dw2 = GetLastError();
#endif
ptr_DimensionTable_File[index1]->Delete() ;
END_

Re: Cannot delete a memory mapped file at end of program by Igor

Igor
Sat Jun 04 13:02:03 CDT 2005

"Peter Nolan" <peter@peternolan.com> wrote in message
news:1117907755.979354.26380@g49g2000cwa.googlegroups.com
> wonder if someone can point out what I am doing wrong.....I am
> creating memory mapped files on win2000 using CreateFile and
> CreateFileMapping and MapViewOfFile. At the end of the program I
> figured it would be nice to clean up these files but when I issued
> the del <filename> as a system command (or if I try the DeleteFile
> function) I get a message saying that the file is in use by another
> process.....Is there something else I must do to release a file that
> I have set up using CreateFile and CreateFileMapping and
> MapViewOfFile???

Both CreateFile and CreateFileMapping return HANDLEs. Both handles must
be closed with CloseHandle. You seem to only close one.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: Cannot delete a memory mapped file at end of program by Tim

Tim
Sun Jun 05 01:02:34 CDT 2005

"Peter Nolan" <peter@peternolan.com> wrote:
>
>//////////////////////////////////////////////////////////////////////////////////////////////
>// When the job ends deleted the wait file, the kill file, and any
>memory mapped files that //
>// have been created by this process.
> //
>//////////////////////////////////////////////////////////////////////////////////////////////
> ptr_WaitFile->Delete() ;
> ptr_KillFile->Delete() ;
> for (index1 = 0 ; index1 < ws_used_memory_mapped_files ; index1++)
> BEGIN_
>
>#if defined (_MSC_VER)
> UnmapViewOfFile(ptr_MemMapBuffer_array[index1]) ;
> DWORD dw1 = GetLastError();
> CloseHandle(ws_HandleForMemMapFile_array[index1]) ;
> DWORD dw2 = GetLastError();
>#endif
> ptr_DimensionTable_File[index1]->Delete() ;
> END_

Please tell me that you have not done this:

#define BEGIN_ {
#define END_ }

There is absolutely no justifiction for that kind of madness.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc