OpenSharedFile(...)

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

OpenSharedFile(...)

Post by mk-soft »

Property times again the case which I a file read in must where another program the file still to write opened.
There pure basic always the file for others the access closes has I now a (dirty) method found these to go around.

Hope the purebasic soon for files also Shared to open can.

Bugfix: #INVALID_HANDLE_VALUE

Code: Select all

#FILE_SHARE_DELETE = 4 ; NT4
#FILE_SHARE_READWRITE = #FILE_SHARE_READ | #FILE_SHARE_WRITE

Procedure OpenSharedFile(ID, FileName.s, DesiredAccess = #GENERIC_READ, ShareMode = #FILE_SHARE_READWRITE, TempFile.s = "temp.tmp")
 
  Protected hFile, addr, result
  
  hFile = CreateFile_(FileName, DesiredAccess, ShareMode, 0, #OPEN_ALWAYS, #FILE_ATTRIBUTE_NORMAL, 0)
  
  If hFile = #INVALID_HANDLE_VALUE
    result = 0
  Else
    result = OpenFile(ID, TempFile)
    If result
      If ID = #PB_Any
        addr = IsFile(result)
        CloseHandle_(FileID(result))
      Else
        addr = IsFile(ID)
        CloseHandle_(FileID(ID))
      EndIf
      PokeI(addr, hFile)
    Else
      CloseHandle_(hFile)
      ProcedureReturn 0
    EndIf
  EndIf
 
  ProcedureReturn result
  
EndProcedure
GT
Michael
Last edited by mk-soft on Fri Nov 11, 2011 5:08 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: OpenSharedFile(...)

Post by mk-soft »

For desiredaccess and sharemode show msdn

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

GT :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply