Repository: files-community/Files
File: src/Files.App/Utils/Shell/PreviewHandler.cs (C#)

Code before:
			previewHandler = previewHandlerObject as IPreviewHandler;

			if (previewHandler == null)
			{
				throw new COMException(cannotCreate);
			}
			var objectWithSite = previewHandlerObject as IObjectWithSite;
			if (objectWithSite == null)
				throw new COMException(cannotCast);
			hr = objectWithSite.SetSite(comWrappers.GetOrCreateComInterfaceForObject(comSite, CreateComInterfaceFlags.None));
			if (hr < 0)
				throw new COMException(cannotSetSite, hr);
			visuals = previewHandlerObject as IPreviewHandlerVisuals;
		}

		#region Initialization interfaces

		[Flags]
		public enum STGM
		{
			STGM_READ = 0x00000000,
			STGM_WRITE = 0x00000001,
			STGM_READWRITE = 0x00000002,
		}

		const int E_NOTIMPL = unchecked((int)0x80004001);

		[GeneratedComInterface, Guid("0000000c-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		public partial interface IStream
		{
			// ISequentialStream portion
			void Read([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1), Out] byte[] pv, int cb, nint pcbRead);
			void Write([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] pv, int cb, nint pcbWritten);

			// IStream portion
			void Seek(long dlibMove, int dwOrigin, nint plibNewPosition);
			void SetSize(long libNewSize);
			void CopyTo(IStream pstm, long cb, nint pcbRead, nint pcbWritten);
			void Commit(int grfCommitFlags);
			void Revert();
			void LockRegion(long libOffset, long cb, int dwLockType);
			void UnlockRegion(long libOffset, long cb, int dwLockType);
		}

		[GeneratedComInterface, Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		internal partial interface IInitializeWithStream
		{
			[PreserveSig]
			int Initialize(IStream psi, STGM grfMode);
		}


Review comment (suggestion):
Can you use `Windows.Win32.Foundation.HRESULT.E_NOTIMPL` instead?
Probably you have to add `E_NOTIMPL` to `NativeMethods.txt`.

Code after:
				throw new COMException(cannotCreate, hr);
			var previewHandlerObject = comWrappers.GetOrCreateObjectForComInstance(pph, CreateObjectFlags.UniqueInstance);
			previewHandler = previewHandlerObject as IPreviewHandler;

			if (previewHandler == null)
			{
				throw new COMException(cannotCreate);
			}
			var objectWithSite = previewHandlerObject as IObjectWithSite;
			if (objectWithSite == null)
				throw new COMException(cannotCast);
			hr = objectWithSite.SetSite(comWrappers.GetOrCreateComInterfaceForObject(comSite, CreateComInterfaceFlags.None));
			if (hr < 0)
				throw new COMException(cannotSetSite, hr);
			visuals = previewHandlerObject as IPreviewHandlerVisuals;
		}

		#region Initialization interfaces

		[GeneratedComInterface, Guid("0000000c-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		public partial interface IStream
		{
			// ISequentialStream portion
			void Read([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1), Out] byte[] pv, int cb, nint pcbRead);
			void Write([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] pv, int cb, nint pcbWritten);

			// IStream portion
			void Seek(long dlibMove, int dwOrigin, nint plibNewPosition);
			void SetSize(long libNewSize);
			void CopyTo(IStream pstm, long cb, nint pcbRead, nint pcbWritten);
			void Commit(int grfCommitFlags);
			void Revert();
			void LockRegion(long libOffset, long cb, int dwLockType);
			void UnlockRegion(long libOffset, long cb, int dwLockType);
		}

		[GeneratedComInterface, Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		internal partial interface IInitializeWithStream
		{
			[PreserveSig]
			int Initialize(IStream psi, STGM grfMode);
		}

		[GeneratedComInterface, Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		internal partial interface IInitializeWithStreamNative
		{
			[PreserveSig]
			int Initialize(IntPtr psi, STGM grfMode);
		}

		static readonly Guid IInitializeWithStreamIid = Guid.ParseExact("b824b49d-22ac-4161-ac8a-9916e8fa3f7f", "d");