Forum > General
After the fileopen operation, the file using memStream.LoadFromFile is occupied
(1/1)
Jzhen:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- result:=True; FFileHandle:=fileopen(filename,fmopenreadwrite); if FFileHandle=invalid_handle_value then begin //raise exception.Create('failed to open or create file'); result:=False; end; try FFilesize:=Windows.GetFileSize(FFileHandle,nil); FMapHandle:=createfilemapping(Ffilehandle,nil,Page_readwrite,0,FFilesize,nil); if FMapHandle=0 then BEGIN //raise exception.Create('failed to create file mapping'); result:=False; END; finally closehandle(FFileHandle); end; try Fdata:=mapviewoffile(FMapHandle,file_map_all_access,0,0,ffilesize); if fdata=nil then BEGIN //raise exception.Create('failed to map view of file '); result:=False; END; finally closehandle(FMapHandle); end; memStream := TmemoryStream.Create; memStream.LoadFromFile(filename);
After using fileopen to operate the file, use memStream. LoadFromFile (filename) to call the file again, and prompt that the file is occupied. Is there any missing way for me to close it
TRon:
Not my area of expertise but after a successful mapviewoffile aren't you suppose to use UnMapViewOfFile function ?
see also: https://learn.microsoft.com/en-us/windows/win32/memory/creating-a-view-within-a-file
KodeZwerg:
--- Quote from: TRon on February 07, 2023, 10:38:23 am ---Not my area of expertise but after a successful mapviewoffile aren't you suppose to use UnMapViewOfFile function ?
--- End quote ---
You was a little faster than me and you are correct!
@Jzhen try to explain what you try to do at all?!
Jzhen:
--- Quote from: TRon on February 07, 2023, 10:38:23 am ---Not my area of expertise but after a successful mapviewoffile aren't you suppose to use UnMapViewOfFile function ?
--- Quote from: KodeZwerg on February 07, 2023, 10:55:59 am ---
--- Quote from: TRon on February 07, 2023, 10:38:23 am ---Not my area of expertise but after a successful mapviewoffile aren't you suppose to use UnMapViewOfFile function ?
--- End quote ---
You was a little faster than me and you are correct!
@Jzhen try to explain what you try to do at all?!
--- End quote ---
see also: https://learn.microsoft.com/en-us/windows/win32/memory/creating-a-view-within-a-file
--- End quote ---
Thank you for solving the problem. I unmaps a mapped view of a file from the calling process's address space at the end of LoadFromFile, so this problem occurred. The cancel operation is successful before LoadFromFile.
Navigation
[0] Message Index