VirtualDesktop: Broken in 22621?

It seems that the tool is broken again in Win11 on 10.0.22621 Build 22621.

I am getting this error (with the VirtualDesktopInsider version, but I tried all, none works):

VirtualDesktopInsider.exe -GetCurrentDesktop -Calc:+1 -MoveWindowHandle: 1775152

Unhandled Exception: System.TypeInitializationException: The type initializer for 'VirtualDesktop.DesktopManager' threw an exception. ---> System.InvalidCastException: Specified cast is not valid.
   at VirtualDesktop.IServiceProvider10.QueryService(Guid& service, Guid& riid)
   at VirtualDesktop.DesktopManager..cctor()
   --- End of inner exception stack trace ---
   at VirtualDesktop.Desktop.get_Current()
   at VDeskTool.Program.Main(String[] args)

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 1
  • Comments: 22 (8 by maintainers)

Most upvoted comments

Hello @slnz00,

thank you for your very valuable information and the great script slnz00/VirtualDesktopDumper

I will integrate the won informations soon.

Greetings

Markus

Hey,

Inspired by @NyaMisty’s solution (GetVirtualDesktopAPI_DIA), I created a dumper that works with the latest versions of Windows 11:

slnz00/VirtualDesktopDumper

I set up some virtual machines and created dumps for all the current live releases (including the insider versions). You can find these dumps in the dumper’s repository.

I also tested your latest 23H2 release (v1.15), and it works great for all versions after 22621.2215, except for the current canary build (25941.1000) where they reintroduced the SwitchDesktopAndMoveForegroundView function which was previously removed and caused issues in 22621.2215.

A new IVirtualDesktop interface GUID has also been introduced. It can be extracted using the IID_IVirtualDesktop2 symbol. However, it seems that using the old GUID still works and does not cause any issues.

Released a new version of VirtualDesktop today.

VirtualDesktop11-23H2.cs is intended to work with Windows 11 22H2 beginning with release 2215 and with the Insider versions of Windows 11.

As I do not have a test environment, this is associated with certain uncertainties…

Greetings

Markus

This seems to work for the latest Windows versions:

// Windows 11 23H2
MIDL_INTERFACE("3F07F4BE-B107-441A-AF0F-39D82529072C")
IVirtualDesktop1123H2 : public IUnknown
{
public:
	virtual HRESULT STDMETHODCALLTYPE IsViewVisible(
		IApplicationView * pView,
		int* pfVisible) = 0;

	virtual HRESULT STDMETHODCALLTYPE GetID(
		GUID* pGuid) = 0;
};


// Windows 11 23H2
MIDL_INTERFACE("A3175F2D-239C-4BD2-8AA0-EEBA8B0B138E")
IVirtualDesktopManagerInternal1123H2 : public IUnknown
{
public:
	virtual HRESULT STDMETHODCALLTYPE GetCount(
		UINT * pCount) = 0;

	virtual HRESULT STDMETHODCALLTYPE MoveViewToDesktop(
		IApplicationView* pView,
		IVirtualDesktop1123H2* pDesktop) = 0;

	// Since build 10240
	virtual HRESULT STDMETHODCALLTYPE CanViewMoveDesktops(
		IApplicationView* pView,
		int* pfCanViewMoveDesktops) = 0;

	virtual HRESULT STDMETHODCALLTYPE GetCurrentDesktop(
//		HWND hWndOrMon,
		IVirtualDesktop1123H2** desktop) = 0;

	//// Since build 22H2
	//virtual HRESULT STDMETHODCALLTYPE GetAllCurrentDesktops(
	//	IObjectArray** ppDesktops) = 0;

	virtual HRESULT STDMETHODCALLTYPE GetDesktops(
	//	HWND hWndOrMon,
		IObjectArray** ppDesktops) = 0;

	virtual HRESULT STDMETHODCALLTYPE GetAdjacentDesktop(
		IVirtualDesktop1123H2* pDesktopReference,
		AdjacentDesktop uDirection,
		IVirtualDesktop1123H2** ppAdjacentDesktop) = 0;

	virtual HRESULT STDMETHODCALLTYPE SwitchDesktop(
	//	HWND hWndOrMon,
		IVirtualDesktop1123H2* pDesktop) = 0;

	// Since build 23H2
	virtual HRESULT STDMETHODCALLTYPE SwitchDesktopAndMoveForegroundView(
		IVirtualDesktop1123H2* pDesktop) = 0;

	virtual HRESULT STDMETHODCALLTYPE CreateDesktopW(
//		HWND hWndOrMon,
		IVirtualDesktop1123H2** ppNewDesktop) = 0;

	virtual HRESULT STDMETHODCALLTYPE MoveDesktop(
		IVirtualDesktop1123H2* pDesktop,
//		HWND hWndOrMon,
		int index) = 0;

	virtual HRESULT STDMETHODCALLTYPE RemoveDesktop(
		IVirtualDesktop1123H2* pRemove,
		IVirtualDesktop1123H2* pFallbackDesktop) = 0;

	// Since build 10240
	virtual HRESULT STDMETHODCALLTYPE FindDesktop(
		GUID* desktopId,
		IVirtualDesktop1123H2** ppDesktop) = 0;

	virtual HRESULT STDMETHODCALLTYPE GetDesktopSwitchIncludeExcludeViews(
		IVirtualDesktop1123H2 desktop,
		IObjectArray** unknown1,
		IObjectArray** unknown2) = 0;

	virtual HRESULT STDMETHODCALLTYPE SetDesktopName(
		IVirtualDesktop1123H2 desktop,
		PCSTR name) = 0;

	virtual HRESULT STDMETHODCALLTYPE SetDesktopWallpaper(IVirtualDesktop1123H2 desktop, PCSTR path) = 0;
	virtual HRESULT STDMETHODCALLTYPE UpdateWallpaperPathForAllDesktops(PCSTR path) = 0;
	virtual HRESULT STDMETHODCALLTYPE CopyDesktopState(IApplicationView pView0, IApplicationView pView1) = 0;
	//virtual HRESULT STDMETHODCALLTYPE GetDesktopIsPerMonitor(int* pResult) = 0;
	//virtual HRESULT STDMETHODCALLTYPE SetDesktopIsPerMonitor(bool state) = 0;
};

// Windows 11 23H2
MIDL_INTERFACE("B287FA1C-7771-471A-A2DF-9B6B21F0D675")
IVirtualDesktopNotification1123H2 : public IUnknown
{
public:
	virtual HRESULT STDMETHODCALLTYPE VirtualDesktopCreated(
		IObjectArray * p0,
		IVirtualDesktop1123H2* pDesktop) = 0;

	virtual HRESULT STDMETHODCALLTYPE VirtualDesktopDestroyBegin(
		IObjectArray* p0,
		IVirtualDesktop1123H2* pDesktopDestroyed,
		IVirtualDesktop1123H2* pDesktopFallback) = 0;

	virtual HRESULT STDMETHODCALLTYPE VirtualDesktopDestroyFailed(
		IObjectArray* p0,
		IVirtualDesktop1123H2* pDesktopDestroyed,
		IVirtualDesktop1123H2* pDesktopFallback) = 0;

	virtual HRESULT STDMETHODCALLTYPE VirtualDesktopDestroyed(
		IObjectArray* p0,
		IVirtualDesktop1123H2* pDesktopDestroyed,
		IVirtualDesktop1123H2* pDesktopFallback) = 0;

	virtual HRESULT STDMETHODCALLTYPE Unknown1(
		int nNumber) = 0;

	virtual HRESULT STDMETHODCALLTYPE VirtualDesktopMoved(
		IObjectArray* p0,
		IVirtualDesktop1123H2* pdesktop,
		int nFromIndex, int nToIndex) = 0;

	virtual HRESULT STDMETHODCALLTYPE VirtualDesktopRenamed(
		IVirtualDesktop1123H2* pdesktop,
		PCSTR name) = 0;

	virtual HRESULT STDMETHODCALLTYPE ViewVirtualDesktopChanged(
		IApplicationView* pView) = 0;

	virtual HRESULT STDMETHODCALLTYPE CurrentVirtualDesktopChanged(
		IObjectArray* p0,
		IVirtualDesktop1123H2* pDesktopOld,
		IVirtualDesktop1123H2* pDesktopNew) = 0;

	virtual HRESULT STDMETHODCALLTYPE VirtualDesktopWallpaperChanged(
		IVirtualDesktop1123H2* pdesktop,
		PCSTR path) = 0;
};
//   https://gitter.im/glsorre/amethystwindows?at=5ffd913403529b296be5e65d
//HRESULT Proc3(/* Stack Offset: 8 */[In] IObjectArray* p0, /* Stack Offset: 16 */[In] IVirtualDesktop* p1);
//HRESULT Proc4(/* Stack Offset: 8 */[In] IObjectArray* p0, /* Stack Offset: 16 */[In] IVirtualDesktop* p1, /* Stack Offset: 24 */[In] IVirtualDesktop* p2);
//HRESULT Proc5(/* Stack Offset: 8 */[In] IObjectArray* p0, /* Stack Offset: 16 */[In] IVirtualDesktop* p1, /* Stack Offset: 24 */[In] IVirtualDesktop* p2);
//HRESULT Proc6(/* Stack Offset: 8 */[In] IObjectArray* p0, /* Stack Offset: 16 */[In] IVirtualDesktop* p1, /* Stack Offset: 24 */[In] IVirtualDesktop* p2);
//HRESULT Proc7(/* Stack Offset: 8 */[In] int p0);
//HRESULT Proc8(/* Stack Offset: 8 */[In] IObjectArray* p0, /* Stack Offset: 16 */[In] IVirtualDesktop* p1, /* Stack Offset: 24 */[In] int p2, /* Stack Offset: 32 */[In] int p3);
//HRESULT Proc9(/* Stack Offset: 8 */[In] IVirtualDesktop* p0, /* Stack Offset: 16 */[In] FC_USER_MARSHAL* p1);
//HRESULT Proc10(/* Stack Offset: 8 */[In] IApplicationView* p0);
//HRESULT Proc11(/* Stack Offset: 8 */[In] IObjectArray* p0, /* Stack Offset: 16 */[In] IVirtualDesktop* p1, /* Stack Offset: 24 */[In] IVirtualDesktop* p2);
//HRESULT Proc12(/* Stack Offset: 8 */[In] IVirtualDesktop* p0, /* Stack Offset: 16 */[In] FC_USER_MARSHAL* p1);
//}


// Windows 11 23H2
MIDL_INTERFACE("0CD45E71-D927-4F15-8B0A-8FEF525337BF")	// W11: UNCHANGED?
IVirtualDesktopNotificationService1123H2 : public IUnknown
{
public:
	virtual HRESULT STDMETHODCALLTYPE Register(
		IVirtualDesktopNotification1123H2* pNotification,
		DWORD * pdwCookie) = 0;

	virtual HRESULT STDMETHODCALLTYPE Unregister(
		DWORD dwCookie) = 0;
};

However, there is still 1 problem: the CurrentVirtualDesktopChanged notification never happens!

ViewVirtualDesktopChanged arrives correctly, but CurrentVirtualDesktopChanged does not. What could be the reason?

Regards!