Repository: files-community/Files
File: src/Files.App/Services/Windows/WindowsWallpaperService.cs (C#)

Code before:
	public sealed class WindowsWallpaperService : IWindowsWallpaperService
	{
		/// <inheritdoc/>
		public unsafe void SetDesktopWallpaper(string szPath)
		{
			using ComPtr<IDesktopWallpaper> pDesktopWallpaper = default;
			var IID_DesktopWallpaper = typeof(IDesktopWallpaper).GUID;
			var CLSID_desktopWallpaper = typeof(DesktopWallpaper).GUID;

			HRESULT hr = PInvoke.CoCreateInstance(
				&CLSID_desktopWallpaper,
				null,
				CLSCTX.CLSCTX_LOCAL_SERVER,
				&IID_DesktopWallpaper,
				(void**)pDesktopWallpaper.GetAddressOf())
			.ThrowOnFailure();

			// Get total count of all monitors available
			hr = pDesktopWallpaper.Get()->GetMonitorDevicePathCount(out var dwMonitorCount)
				.ThrowOnFailure();

			fixed (char* pszPath = szPath)
			{
				PWSTR pMonitorID = default;

				// Set the selected image file as wallpaper to all monitors available
				for (uint dwIndex = 0u; dwIndex < dwMonitorCount; dwIndex++)
				{
					hr = pDesktopWallpaper.Get()->GetMonitorDevicePathAt(dwIndex, &pMonitorID).ThrowOnFailure();
					hr = pDesktopWallpaper.Get()->SetWallpaper(pMonitorID, pszPath).ThrowOnFailure();

					pMonitorID = default;
				}
			}
		}

		/// <inheritdoc/>
		public unsafe void SetDesktopSlideshow(string[] aszPaths)
		{
			using ComPtr<IDesktopWallpaper> pDesktopWallpaper = default;
			var IID_DesktopWallpaper = typeof(IDesktopWallpaper).GUID;
			var CLSID_desktopWallpaper = typeof(DesktopWallpaper).GUID;

			HRESULT hr = PInvoke.CoCreateInstance(
				&CLSID_desktopWallpaper,
				null,
				CLSCTX.CLSCTX_LOCAL_SERVER,
				&IID_DesktopWallpaper,
				(void**)pDesktopWallpaper.GetAddressOf())
			.ThrowOnFailure();


Review comment (suggestion):
```suggestion
				// Set the selected image file as wallpaper for all available monitors
```

Code after:
	public sealed class WindowsWallpaperService : IWindowsWallpaperService
	{
		/// <inheritdoc/>
		public unsafe void SetDesktopWallpaper(string szPath)
		{
			// Instantiate IDesktopWallpaper
			using ComPtr<IDesktopWallpaper> pDesktopWallpaper = default;
			HRESULT hr = pDesktopWallpaper.CoCreateInstance<DesktopWallpaper>().ThrowOnFailure();

			// Get total count of all available monitors
			hr = pDesktopWallpaper.Get()->GetMonitorDevicePathCount(out var dwMonitorCount).ThrowOnFailure();

			fixed (char* pszPath = szPath)
			{
				PWSTR pMonitorId = default;

				// Set the selected image file as wallpaper for all available monitors
				for (uint dwIndex = 0u; dwIndex < dwMonitorCount; dwIndex++)
				{
					// Set the wallpaper
					hr = pDesktopWallpaper.Get()->GetMonitorDevicePathAt(dwIndex, &pMonitorId).ThrowOnFailure();
					hr = pDesktopWallpaper.Get()->SetWallpaper(pMonitorId, pszPath).ThrowOnFailure();

					pMonitorId = default;
				}
			}
		}

		/// <inheritdoc/>
		public unsafe void SetDesktopSlideshow(string[] aszPaths)
		{
			// Instantiate IDesktopWallpaper
			using ComPtr<IDesktopWallpaper> pDesktopWallpaper = default;
			HRESULT hr = pDesktopWallpaper.CoCreateInstance<DesktopWallpaper>().ThrowOnFailure();

			uint dwCount = (uint)aszPaths.Length;
			ITEMIDLIST** ppItemIdList = stackalloc ITEMIDLIST*[aszPaths.Length];

			// Get an array of PIDL from the selected image files
			for (uint dwIndex = 0u; dwIndex < dwCount; dwIndex++)
				ppItemIdList[dwIndex] = PInvoke.ILCreateFromPath(aszPaths[dwIndex]);

			// Get an IShellItemArray from the array of the PIDL
			using ComPtr<IShellItemArray> pShellItemArray = default;
			hr = PInvoke.SHCreateShellItemArrayFromIDLists(dwCount, ppItemIdList, pShellItemArray.GetAddressOf()).ThrowOnFailure();

			// Release the allocated PIDL
			for (uint dwIndex = 0u; dwIndex < dwCount; dwIndex++)
				PInvoke.CoTaskMemFree((void*)ppItemIdList[dwIndex]);

			// Set the slideshow and its position