Cc judge whether the local file is open

From , 4 Years ago, written in C#, viewed 52 times.
URL https://pastebin.vip/view/f3935d39
  1.  public class FileStatus
  2.     {
  3.         [DllImport("kernel32.dll")]
  4.         private static extern IntPtr _lopen(string lpPathName, int iReadWrite);
  5.  
  6.         [DllImport("kernel32.dll")]
  7.         private static extern bool CloseHandle(IntPtr hObject);
  8.  
  9.         private const int OF_READWRITE = 2;
  10.  
  11.         private const int OF_SHARE_DENY_NONE = 0x40;
  12.  
  13.         private static readonly IntPtr HFILE_ERROR = new IntPtr(-1);
  14.  
  15.         public static int FileIsOpen(string fileFullName)
  16.         {
  17.             if (!File.Exists(fileFullName))
  18.             {
  19.                 return -1;
  20.             }
  21.  
  22.             IntPtr handle = _lopen(fileFullName, OF_READWRITE | OF_SHARE_DENY_NONE);
  23.  
  24.             if (handle == HFILE_ERROR)
  25.             {
  26.                 return 1;
  27.             }
  28.  
  29.             CloseHandle(handle);
  30.  
  31.             return 0;
  32.         }
  33.     }
  34.  
  35.  
  36. //csharp/6027

Reply to "Cc judge whether the local file is open"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website