diff --git a/PInvoke/CldApi/cfapi.Funcs.cs b/PInvoke/CldApi/cfapi.Funcs.cs
index 23a4d72e..eeea23ca 100644
--- a/PInvoke/CldApi/cfapi.Funcs.cs
+++ b/PInvoke/CldApi/cfapi.Funcs.cs
@@ -872,6 +872,22 @@ namespace Vanara.PInvoke
[PInvokeData("cfapi.h", MSDNShortId = "1CB7955D-E530-4F34-8D67-BC608F8B6AF1")]
public static extern HRESULT CfSetInSyncState(HFILE FileHandle, CF_IN_SYNC_STATE InSyncState, CF_SET_IN_SYNC_FLAGS InSyncFlags, ref USN InSyncUsn);
+ /// Sets the in-sync state for a placeholder file or folder.
+ /// A handle to the placeholder. The caller must have WRITE_DATA or WRITE_DAC access to the placeholder.
+ /// The in-sync state. See CF_IN_SYNC_STATE for more details.
+ /// The in-sync state flags. See CF_SET_IN_SYNC_FLAGS for more details.
+ ///
+ /// When specified, this instructs the platform to only perform in-sync setting if the file still has the same USN value as the one
+ /// passed in. Passing a pointer to a USN value of 0 on input is the same as passing a NULL pointer. On return, this is the final
+ /// USN value after setting the in-sync state.
+ ///
+ /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
+ // https://docs.microsoft.com/en-us/windows/win32/api/cfapi/nf-cfapi-cfsetinsyncstate HRESULT CfSetInSyncState( HANDLE FileHandle,
+ // CF_IN_SYNC_STATE InSyncState, CF_SET_IN_SYNC_FLAGS InSyncFlags, USN *InSyncUsn );
+ [DllImport(Lib.CldApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("cfapi.h", MSDNShortId = "1CB7955D-E530-4F34-8D67-BC608F8B6AF1")]
+ public static extern HRESULT CfSetInSyncState(HFILE FileHandle, CF_IN_SYNC_STATE InSyncState, CF_SET_IN_SYNC_FLAGS InSyncFlags, [In, Optional] IntPtr InSyncUsn);
+
///
/// This sets the pin state of a placeholder, used to represent a user’s intent. Any application (not just the sync provider) can
/// call this function.
diff --git a/UnitTests/PInvoke/CldApi/CldApiTests.cs b/UnitTests/PInvoke/CldApi/CldApiTests.cs
index 5b5b4138..89ea767b 100644
--- a/UnitTests/PInvoke/CldApi/CldApiTests.cs
+++ b/UnitTests/PInvoke/CldApi/CldApiTests.cs
@@ -209,8 +209,7 @@ namespace Vanara.PInvoke.Tests
Assert.That(File.Exists(destFile), Is.True);
using var hFile = GetHFILE(destFile);
- var usn = 0;
- Assert.That(CfSetInSyncState(hFile, CF_IN_SYNC_STATE.CF_IN_SYNC_STATE_IN_SYNC, CF_SET_IN_SYNC_FLAGS.CF_SET_IN_SYNC_FLAG_NONE, ref usn), ResultIs.Successful);
+ Assert.That(CfSetInSyncState(hFile, CF_IN_SYNC_STATE.CF_IN_SYNC_STATE_IN_SYNC, CF_SET_IN_SYNC_FLAGS.CF_SET_IN_SYNC_FLAG_NONE), ResultIs.Successful);
Assert.That(CfSetPinState(hFile, CF_PIN_STATE.CF_PIN_STATE_PINNED, CF_SET_PIN_FLAGS.CF_SET_PIN_FLAG_NONE), ResultIs.Successful);
}
finally
diff --git a/UnitTests/PInvoke/CldApi/CloudSyncProvider.cs b/UnitTests/PInvoke/CldApi/CloudSyncProvider.cs
index 80ac4e04..fce9e9f9 100644
--- a/UnitTests/PInvoke/CldApi/CloudSyncProvider.cs
+++ b/UnitTests/PInvoke/CldApi/CloudSyncProvider.cs
@@ -14,6 +14,7 @@ using Windows.Storage.Provider;
using static Vanara.PInvoke.CldApi;
using static Vanara.PInvoke.Kernel32;
using static Vanara.PInvoke.SearchApi;
+using USN = System.Int64;
namespace Vanara.PInvoke.Tests
{
@@ -172,7 +173,7 @@ namespace Vanara.PInvoke.Tests
public DateTime ChangeTime;
/// The final USN value after create actions are performed.
- public int CreateUsn;
+ public USN CreateUsn;
///
/// The time the file was created in FILETIME format, which is a 64-bit value representing the number of 100-nanosecond intervals
@@ -345,7 +346,7 @@ namespace Vanara.PInvoke.Tests
///
///
///
- public int ConvertToPlaceholder(string relativeFilePath, bool inSync = true, bool dehydrate = false, IntPtr fileIdentity = default, uint fileIdentityLength = 0)
+ public USN ConvertToPlaceholder(string relativeFilePath, bool inSync = true, bool dehydrate = false, IntPtr fileIdentity = default, uint fileIdentityLength = 0)
{
CfOpenFileWithOplock(relativeFilePath, CF_OPEN_FILE_FLAGS.CF_OPEN_FILE_FLAG_EXCLUSIVE, out var hCfFile).ThrowIfFailed();
using (hCfFile)
@@ -413,7 +414,7 @@ namespace Vanara.PInvoke.Tests
///
///
///
- public int ConvertToPlaceholder(HFILE fileHandle, bool inSync = true, bool dehydrate = false, IntPtr fileIdentity = default, uint fileIdentityLength = 0)
+ public USN ConvertToPlaceholder(HFILE fileHandle, bool inSync = true, bool dehydrate = false, IntPtr fileIdentity = default, uint fileIdentityLength = 0)
{
var flags = (inSync ? CF_CONVERT_FLAGS.CF_CONVERT_FLAG_MARK_IN_SYNC : 0) | (dehydrate ? CF_CONVERT_FLAGS.CF_CONVERT_FLAG_DEHYDRATE : 0);
CfConvertToPlaceholder(fileHandle, fileIdentity, fileIdentityLength, flags, out var usn).ThrowIfFailed();
@@ -425,7 +426,7 @@ namespace Vanara.PInvoke.Tests
/// The file information of the file.
/// if set to , the file is synchronized.
/// The final USN value for the file.
- public int CreatePlaceholderFromFile(string relativeFilePath, FileInfo fileInfo, bool inSync = true)
+ public USN CreatePlaceholderFromFile(string relativeFilePath, FileInfo fileInfo, bool inSync = true)
{
using var pRelativeName = new SafeCoTaskMemString(relativeFilePath);
var ph = new PlaceholderInfo[] { PlaceHolderFileInfo.CreateFromFile(fileInfo, inSync, relativeFilePath) };