Sam Hobbs

Sam Hobbs

  • 51
  • 29.3k
  • 2.1m

IShellWindows::FindWindowSW

Jun 16 2011 11:37 PM
How to call IShellWindows::FindWindowSW with swClass=SWC_BROWSER to get a browser window from a cookie (swfwOptions=SWFO_COOKIEPASSED)? Note that if you don't know, it is unlikely you can guess.

The attached project has a C++ managed program that calls FindWindowSW in unmanged code. I am hoping to get an unmanaged program working so I can do the corresponding in managed code; especially C#.

The FindWindowSW documentation says that pvarLoc is a "VARIANT of type VT_VARIANT | VT_BYREF" but it has been suggested that for a cookie just use a VT_I4 without redirection. I have tried many combinations and nothing that I have tried works.

The attached program uses DShellWindowsEvents.WindowRegistered in managed code to monitor IE windows to get cookie values. When a new window opens, it calls FindWindowSW in unmanaged code.

The following is a simplified version of how I am calling FindWindowSW. The commented code shows some of the combinations I have tried.


const int Options = SWFO_COOKIEPASSED | SWFO_NEEDDISPATCH | SWFO_INCLUDEPENDING;
//VARIANT CookieVariant;
//CookieVariant.vt = VT_I4;
//CookieVariant.lVal = Cookie;
//VARIANT pvarLoc;
//pvarLoc.vt = VT_VARIANT | VT_BYREF;
//pvarLoc.pvarVal = &CookieVariant;
VARIANT pvarLoc;
pvarLoc.vt = VT_I4;
pvarLoc.lVal = Cookie;
_variant_t Empty;
hr = pshellws->FindWindowSW(&pvarLoc, &Empty, 0xFFFF/*SWC_BROWSER*/, &hwnd, Options, &dp);

Attachment: managedmonitorie.zip