Slion / VirtualDesktop

C# wrapper for the Virtual Desktop API on Windows 11.
MIT License
21 stars 9 forks source link

Support OS Build 22621.2215 #1

Closed Slion closed 1 year ago

Slion commented 1 year ago

Windows 11 OS Build 22621.2134 was working fine. However since 22H2 August 2023 update and OS Build 22621.2215 VirtualDesktop is broken again.

Checkout the forks of https://github.com/t1m0thyj/GetVirtualDesktopAPI_DIA/network and try use them to reverse engineer the latest changes.

Since we can also have breakage between minor OS Build update we should incorporate minor OS Build in our ID resolution system.

mzomparelli commented 1 year ago

I have already forked that and made some changes to it (My version dumps IApplicationView too, but I still can't dump the GUID for it unless it's named. I do however know how to find it even when OleViewDotNet can't. I'm installing the three insider builds now. I'm running Win 11 22621.2215 (non-insider) on a VM already and it has the latest updates. It works with the interfaces I mentioned in that other thread.

mzomparelli commented 1 year ago

Check that you are using these for your 22621.2215 build

[ComImport]
    [Guid("A3175F2D-239C-4BD2-8AA0-EEBA8B0B138E")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IVirtualDesktopManagerInternal
    {
        int GetCount();
        void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop desktop);
        bool CanViewMoveDesktops(IApplicationView pView);
        IVirtualDesktop GetCurrentDesktop();
        //IObjectArray GetAllCurrentDesktops();
        IObjectArray GetDesktops();
        IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, int uDirection);
        void SwitchDesktop(IVirtualDesktop desktop);
        IVirtualDesktop CreateDesktopW();
        void MoveDesktop(IVirtualDesktop desktop, int nIndex);
        void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
        IVirtualDesktop FindDesktop(in Guid desktopId);
        void GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop desktop, out IObjectArray o1, out IObjectArray o2);
        void SetDesktopName(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string name);
        void SetDesktopWallpaper(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string path);
        void UpdateWallpaperPathForAllDesktops([MarshalAs(UnmanagedType.HString)] string path);
        void CopyDesktopState(IApplicationView pView0, IApplicationView pView1);
        IVirtualDesktop CreateRemoteDesktop([MarshalAs(UnmanagedType.HString)] string name);
        void SwitchRemoteDesktop(IVirtualDesktop desktop);
        void SwitchDesktopWithAnimation(IVirtualDesktop desktop);
        IVirtualDesktop GetLastActiveDesktop();
        void WaitForAnimationToComplete();
    }

[ComImport]
    [Guid("B287FA1C-7771-471A-A2DF-9B6B21F0D675")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVirtualDesktopNotification
    {
        void VirtualDesktopCreated(IVirtualDesktop pDesktop);
        void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopMoved(IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo);
        void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string name);
        void ViewVirtualDesktopChanged(IntPtr pView);
        void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew);
        void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string path);
        IVirtualDesktop VirtualDesktopSwitched();
        IVirtualDesktop RemoteVirtualDesktopConnected();
    }

[ComImport]
    [Guid("3F07F4BE-B107-441A-AF0F-39D82529072C")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVirtualDesktop
    {
        bool IsViewVisible(IApplicationView view);
        Guid GetID();
        void GetName([MarshalAs(UnmanagedType.HString)] out string name);
        void GetWallpaperPath([MarshalAs(UnmanagedType.HString)] out string name);
        void IsRemote(out bool isRemote);
    }
mzomparelli commented 1 year ago

I have all the insiders installed and now I'm just waiting for all the updates image

Slion commented 1 year ago

@mzomparelli I would need to ids for all those interfaces:

            <string>IApplicationView,{372E1D3B-38D3-42E4-A15B-8AB2B178F513}</string>
            <string>IApplicationViewCollection,{1841C6D7-4F9D-42C0-AF41-8747538F10E5}</string>
            <string>IObjectArray,{92CA9DCD-5622-4BBA-A805-5E9F541BD8C9}</string>
            <string>IServiceProvider,{6D5140C1-7436-11CE-8034-00AA006009FA}</string>
            <string>IVirtualDesktop,{536D3495-B208-4CC9-AE26-DE8111275BF8}</string>
            <string>IVirtualDesktopManager,{A5CD92FF-29BE-454C-8D04-D82879FB3F1B}</string>
            <string>IVirtualDesktopManagerInternal,{B2F925B9-5A0F-4D2E-9F4D-2B1507593C10}</string>
            <string>IVirtualDesktopNotification,{cd403e52-deed-4c13-b437-b98380f2b1e8}</string>
            <string>IVirtualDesktopNotificationService,{0cd45e71-d927-4f15-8b0a-8fef525337bf}</string>
            <string>IVirtualDesktopPinnedApps,{4CE81583-1E4C-4632-A621-07A53543148F}</string>

Right now it fails to load IApplicationViewCollection for instance.

Slion commented 1 year ago

Working on this branch: https://github.com/Slion/VirtualDesktop/tree/feature_os_build_revision

mzomparelli commented 1 year ago

Looking at the GUIDs you just posted, you have the wrong IVirtualDesktop, IVirtualDesktopManagerInternal, and IVirtualDesktopNotification for 22H2

Try these:

[ComImport]
    [Guid("3F07F4BE-B107-441A-AF0F-39D82529072C")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVirtualDesktop
    {
        bool IsViewVisible(IApplicationView view);
        Guid GetID();
        void GetName([MarshalAs(UnmanagedType.HString)] out string name);
        void GetWallpaperPath([MarshalAs(UnmanagedType.HString)] out string name);
        void IsRemote(out bool isRemote);
    }

[ComImport]
    [Guid("A3175F2D-239C-4BD2-8AA0-EEBA8B0B138E")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IVirtualDesktopManagerInternal
    {
        int GetCount();
        void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop desktop);
        bool CanViewMoveDesktops(IApplicationView pView);
        IVirtualDesktop GetCurrentDesktop();
        //IObjectArray GetAllCurrentDesktops();
        IObjectArray GetDesktops();
        IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, int uDirection);
        void SwitchDesktop(IVirtualDesktop desktop);
        IVirtualDesktop CreateDesktopW();
        void MoveDesktop(IVirtualDesktop desktop, int nIndex);
        void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
        IVirtualDesktop FindDesktop(in Guid desktopId);
        void GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop desktop, out IObjectArray o1, out IObjectArray o2);
        void SetDesktopName(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string name);
        void SetDesktopWallpaper(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string path);
        void UpdateWallpaperPathForAllDesktops([MarshalAs(UnmanagedType.HString)] string path);
        void CopyDesktopState(IApplicationView pView0, IApplicationView pView1);
        IVirtualDesktop CreateRemoteDesktop([MarshalAs(UnmanagedType.HString)] string name);
        void SwitchRemoteDesktop(IVirtualDesktop desktop);
        void SwitchDesktopWithAnimation(IVirtualDesktop desktop);
        IVirtualDesktop GetLastActiveDesktop();
        void WaitForAnimationToComplete();
    }

[ComImport]
    [Guid("B287FA1C-7771-471A-A2DF-9B6B21F0D675")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVirtualDesktopNotification
    {
        void VirtualDesktopCreated(IVirtualDesktop pDesktop);
        void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopMoved(IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo);
        void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string name);
        void ViewVirtualDesktopChanged(IntPtr pView);
        void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew);
        void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string path);
        IVirtualDesktop VirtualDesktopSwitched();
        IVirtualDesktop RemoteVirtualDesktopConnected();
    }
Slion commented 1 year ago

I know, those were just the ones for 22621 before 2215. But I would need the new ids from all mentioned interfaces. Not just those three.

mzomparelli commented 1 year ago

I'm running 22621.2215 and it says it's fully updated. I think maybe we have different versions still. Send me your twinui.pcshell.dll

The others have not changed. You just use the ones you have. You may need to update your IApplicationView

[ComImport]
    [Guid("372e1d3b-38d3-42e4-a15b-8ab2b178f513")]
    [InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
    public interface IApplicationView
    {
        void SetFocus();
        void SwitchTo();
        void TryInvokeBack(ref IntPtr /* IAsyncCallback* */ callback);
        void GetThumbnailWindow(out IntPtr hwnd);
        void GetMonitor(out IntPtr /* IImmersiveMonitor */ immersiveMonitor);
        void GetVisibility(out int visibility);
        void SetCloak(APPLICATION_VIEW_CLOAK_TYPE cloakType, int unknown);
        void GetPosition(ref Guid guid /* GUID for IApplicationViewPosition */, out IntPtr /* IApplicationViewPosition** */ position);
        void SetPosition(ref IntPtr /* IApplicationViewPosition* */ position);
        void InsertAfterWindow(IntPtr hwnd);
        void GetExtendedFramePosition(out Rect rect);
        void GetAppUserModelId([MarshalAs(UnmanagedType.LPWStr)] out string id);
        void SetAppUserModelId(string id);
        void IsEqualByAppUserModelId(string id, out int result);
        void GetViewState(out int state);
        void SetViewState(int state);
        void GetNeediness(out int neediness);
        void GetLastActivationTimestamp(out long timestamp);
        void SetLastActivationTimestamp(long timestamp);
        void GetVirtualDesktopId(out Guid guid);
        void SetVirtualDesktopId(ref Guid guid);
        void GetShowInSwitchers(out int flag);
        void SetShowInSwitchers(int flag);
        void GetScaleFactor(out int factor);
        void CanReceiveInput(out bool canReceiveInput);
        void GetCompatibilityPolicyType(out APPLICATION_VIEW_COMPATIBILITY_POLICY flags);
        void SetCompatibilityPolicyType(APPLICATION_VIEW_COMPATIBILITY_POLICY flags);
        void GetSizeConstraints(IntPtr /* IImmersiveMonitor* */ monitor, out Size size1, out Size size2);
        void GetSizeConstraintsForDpi(int uint1, out Size size1, out Size size2);
        void SetSizeConstraintsForDpi(ref int uint1, ref Size size1, ref Size size2);
        void OnMinSizePreferencesUpdated(IntPtr hwnd);
        void ApplyOperation(ref IntPtr /* IApplicationViewOperation* */ operation);
        void IsTray(out bool isTray);
        void IsInHighZOrderBand(out bool isInHighZOrderBand);
        void IsSplashScreenPresented(out bool isSplashScreenPresented);
        void Flash();
        void GetRootSwitchableOwner(out IApplicationView rootSwitchableOwner);
        void EnumerateOwnershipTree(out IObjectArray ownershipTree);
        void GetEnterpriseId([MarshalAs(UnmanagedType.LPWStr)] out string enterpriseId);
        void GetEnterpriseChromePreference(out int unknown);
        void IsMirrored(out bool isMirrored);
        void GetFrameworkViewType(out int /*FRAMEWORK_VIEW_TYPE*/ unknown);
        void GetCanTab(out int unknown);
        void SetCanTab(int unknown);
        void GetIsTabbed(out int unknown);
        void SetIsTabbed(int unknown);
        void RefreshCanTab();
        void GetIsOccluded(out int unknown);
        void SetIsOccluded(int unknown);
        void UpdateEngagementFlags(int /*VIEW_ENGAGEMENT_FLAGS*/ unknown, int /*VIEW_ENGAGEMENT_FLAGS*/ int2);
        void SetForceActiveWindowAppearance(int unknown);
        void GetLastActivationFILETIME(FILETIME timestamp);
        void GetPersistingStateName([MarshalAs(UnmanagedType.LPWStr)] out string name);
    }
Slion commented 1 year ago

There it is: twinui.pcshell.zip

mzomparelli commented 1 year ago

I hashed your DLL and mine and they are the same. If you follow my instructions then it should work for you as it is for me.

Here I am running zVirtualDesktop on 22621.2215 The screenshot is of DesktopView to show that I have windows on all desktops and the program is handling them fine.

image

mzomparelli commented 1 year ago

Can you try running my Win11 22H2 app and see if that works for you?

https://zomp.co/Downloads/zVirtualDesktop_Win11_22H2.exe

mzomparelli commented 1 year ago

While you test that here is the Windows Server 2022 build 20348.1906 interfaces that are different (for the others use Win11 22H2 compatible):

[ComImport]
    [Guid("f3163e11-6b04-433c-a64b-6f82c9094257")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVirtualDesktopNotification
    {
        void VirtualDesktopCreated(IVirtualDesktop pDesktop);
        void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopIsPerMonitorChanged(int i);
        //void VirtualDesktopMoved(IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo);
        void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string name);
        void ViewVirtualDesktopChanged(IntPtr pView);
        void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew);
        // void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string path);
        // IVirtualDesktop VirtualDesktopSwitched();
        // IVirtualDesktop RemoteVirtualDesktopConnected();
    }

[ComImport]
    [Guid("62FDF88B-11CA-4AFB-8BD8-2296DFAE49E2")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVirtualDesktop
    {
        bool IsViewVisible(IApplicationView view);
        Guid GetID();
        IntPtr GetMonitor(IntPtr monitor);
        void GetName([MarshalAs(UnmanagedType.HString)] out string name);
    }
Dexterously commented 1 year ago

Can you try running my Win11 22H2 app and see if that works for you?

https://zomp.co/Downloads/zVirtualDesktop_Win11_22H2.exe

Even though this branch crashes, and I can't get it to work, I can confirm that this app works in 22621.2215.

So I'm not sure why the project doesn't work for me anymore? Any ideas on how to pin point what's wrong with it?

mzomparelli commented 1 year ago

I pointed out what you need to change. Based on the GUIDs you posted earlier you only need to update the following (any not listed here is just your current one):

[ComImport]
    [Guid("3F07F4BE-B107-441A-AF0F-39D82529072C")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVirtualDesktop
    {
        bool IsViewVisible(IApplicationView view);
        Guid GetID();
        void GetName([MarshalAs(UnmanagedType.HString)] out string name);
        void GetWallpaperPath([MarshalAs(UnmanagedType.HString)] out string name);
        void IsRemote(out bool isRemote);
    }

[ComImport]
    [Guid("A3175F2D-239C-4BD2-8AA0-EEBA8B0B138E")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IVirtualDesktopManagerInternal
    {
        int GetCount();
        void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop desktop);
        bool CanViewMoveDesktops(IApplicationView pView);
        IVirtualDesktop GetCurrentDesktop();
        //IObjectArray GetAllCurrentDesktops();
        IObjectArray GetDesktops();
        IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, int uDirection);
        void SwitchDesktop(IVirtualDesktop desktop);
        IVirtualDesktop CreateDesktopW();
        void MoveDesktop(IVirtualDesktop desktop, int nIndex);
        void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
        IVirtualDesktop FindDesktop(in Guid desktopId);
        void GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop desktop, out IObjectArray o1, out IObjectArray o2);
        void SetDesktopName(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string name);
        void SetDesktopWallpaper(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string path);
        void UpdateWallpaperPathForAllDesktops([MarshalAs(UnmanagedType.HString)] string path);
        void CopyDesktopState(IApplicationView pView0, IApplicationView pView1);
        IVirtualDesktop CreateRemoteDesktop([MarshalAs(UnmanagedType.HString)] string name);
        void SwitchRemoteDesktop(IVirtualDesktop desktop);
        void SwitchDesktopWithAnimation(IVirtualDesktop desktop);
        IVirtualDesktop GetLastActiveDesktop();
        void WaitForAnimationToComplete();
    }

[ComImport]
    [Guid("B287FA1C-7771-471A-A2DF-9B6B21F0D675")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVirtualDesktopNotification
    {
        void VirtualDesktopCreated(IVirtualDesktop pDesktop);
        void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
        void VirtualDesktopMoved(IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo);
        void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string name);
        void ViewVirtualDesktopChanged(IntPtr pView);
        void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew);
        void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string path);
        IVirtualDesktop VirtualDesktopSwitched();
        IVirtualDesktop RemoteVirtualDesktopConnected();
    }
mzomparelli commented 1 year ago

I maintain my own private code. I'd open it up but it's part of my zVirtualDesktop code. I'll work on separating it into a DLL and spin off a new repo for it.

mzomparelli commented 1 year ago

I have completed evaluating the insider builds and have concluded that the current interface for 22H2 should suffice for builds 23531.1001 and 25936.1000