Freigeben über


Junction PInvoke Signatures

Following are the signatures that I needed to enable Junctions through .NET. In another posting I will cover several structs that I had to create. If you are unable to wait for me to post them please let me know and I will get them here sooner.

  /// CloseHandle function
  /// </summary>
  /// <param name="hObject">Handle to an open object.</param>
  /// <returns>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.</returns>
  [System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
  private extern static int CloseHandle(IntPtr hObject);

  /// <summary>
  /// CreateFile function
  /// </summary>
  /// <param name="FileName"></param>
  /// <param name="DesiredAccess"></param>
  /// <param name="ShareMode"></param>
  /// <param name="lpSecurityAttributes"></param>
  /// <param name="CreationDisposition"></param>
  /// <param name="dwFlagsAndAttributes"></param>
  /// <param name="hTemplateFile"></param>
  /// <returns>INVALID_HANDLE_VALUE on error or the handle to file if success</returns>
  [System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
  private extern static IntPtr CreateFile(string FileName, uint DesiredAccess,
                                          uint ShareMode, IntPtr lpSecurityAttributes,
                                          uint CreationDisposition, uint dwFlagsAndAttributes,
                                          IntPtr hTemplateFile);

  /// <summary>
  /// Junction form of DeviceIoControl Win32 function
  /// </summary>
  /// <param name="hDevice">Handle of device opened with CreateFile</param>
  /// <param name="nIoControlCode">Code of DeviceIoControl operation</param>
  /// <param name="rmp">Pointer to a buffer that contains the REPARSE_MOUNTPOINT_DATA_BUFFER data required to perform the operation.</param>
  /// <param name="nBufferSize">Size of the buffer pointed to by lpInBuffer, in bytes.</param>
  /// <param name="lpOutBuffer">Pointer to a buffer that receives the operation's output data.</param>
  /// <param name="lpOutBufferSize">Size of the buffer pointed to by lpOutBuffer, in bytes.</param>
  /// <param name="lpBytesReturned">Receives the size, in bytes, of the data stored into the buffer pointed to by lpOutBuffer. </param>
  /// <param name="lpOverlapped">Pointer to an OVERLAPPED structure. Discarded for this case</param>
  /// <returns>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.</returns>
  [System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
  private extern static bool DeviceIoControl(IntPtr hDevice,
                                              uint nIoControlCode,
                                              REPARSE_MOUNTPOINT_DATA_BUFFER rmp,
                                              uint nBufferSize,
                                              IntPtr lpOutBuffer,
                                              IntPtr lpOutBufferSize,
                                              ref uint lpBytesReturned,
                                              IntPtr lpOverlapped);

  /// <summary>
  /// Junction form of DeviceIoControl Win32 function
  /// </summary>
  /// <param name="hDevice">Handle of device opened with CreateFile</param>
  /// <param name="nIoControlCode">Code of DeviceIoControl operation</param>
  /// <param name="lpInBuffer">Pointer to a buffer.</param>
  /// <param name="nBufferSize">Size of the buffer pointed to by lpInBuffer, in bytes.</param>
  /// <param name="lpOutBuffer">Pointer to a buffer that receives the operation's output data.</param>
  /// <param name="lpOutBufferSize">Size of the buffer pointed to by lpOutBuffer, in bytes.</param>
  /// <param name="lpBytesReturned">Receives the size, in bytes, of the data stored into the buffer pointed to by lpOutBuffer. </param>
  /// <param name="lpOverlapped">Pointer to an OVERLAPPED structure. Discarded for this case</param>
  /// <returns>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.</returns>
  [System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
  private extern static bool DeviceIoControl(IntPtr hDevice,
                                              uint nIoControlCode,
                                              IntPtr lpInBuffer,
                                              IntPtr lpBufferSize,
                                              IntPtr lpvReparseBuf,
                                              int nBufferSize,
                                              ref uint lpBytesReturned,
                                              IntPtr lpOverlapped);

  /// <summary>
  /// Junction form of GetFileAttributes Win32 function
  /// </summary>
  /// <param name="lpFileName">File Name</param>
  /// <returns>The attributes of the specified file or directory, returned in a DWORD, indicates success. 0xFFFFFFFF indicates failure.</returns>
  [System.Runtime.InteropServices.DllImport("Kernel32.dll", SetLastError = true)]
  private extern static uint GetFileAttributes(string FileName);