Hi All,
I'm aware a number of people have asked this around the internet, and that the accepted solution in general uses the SHDocVw.ShellWindows collection. However, this doesn't work properly for me ("Out of memory error" when constructing the class, probably I'm working on a VM which doesn't maintain a collection of windows for taskbar use).
It does look like someone else has already figured it out - in C/C++/C#/Whatever language I'm about to post. I can understand what it does, but I'm too new to COM programming concepts and GUIDs to know what the equivalent functions are in VBA. So, does anyone have any idea how to implement the below in VBA? I've marked up the bits I understand and have an equivalent for, and those that are brand new.
Code in question comes from the solution here.
Unknown:
Known:
Unknown:
In particular, I'm struggling with the typeof(mshtml.IHTMLDocument2).GUID equivalent, and the declaration of what looks like IServiceProvider at the top.
Many thanks in advance.
I'm aware a number of people have asked this around the internet, and that the accepted solution in general uses the SHDocVw.ShellWindows collection. However, this doesn't work properly for me ("Out of memory error" when constructing the class, probably I'm working on a VM which doesn't maintain a collection of windows for taskbar use).
It does look like someone else has already figured it out - in C/C++/C#/Whatever language I'm about to post. I can understand what it does, but I'm too new to COM programming concepts and GUIDs to know what the equivalent functions are in VBA. So, does anyone have any idea how to implement the below in VBA? I've marked up the bits I understand and have an equivalent for, and those that are brand new.
Code in question comes from the solution here.
Unknown:
Code:
[SIZE=2][ComImport]
[Guid("6d5140c1-7436-11ce-8034-00aa006009fa")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IServiceProvider
{
void QueryService(ref Guid guidService, ref Guid riid,
[MarshalAs(UnmanagedType.Interface)] out object IEObj);
}//IServiceProvider
[/SIZE]
Known:
Code:
[SIZE=2] /// <summary></summary>[/SIZE]
[SIZE=2] /// Gets the IWebBrowser2 object based on Window Handle
///
///
The Hanlde of Internet Explore_Server
/// <returns>IWebBroswer2 Object</returns>
private IWebBrowser2 GetIEObjFromHnd(IntPtr theHwnd)
{
IWebBrowser2 aWB=null;
System.Guid IID_IHTMLDocument = typeof(mshtml.IHTMLDocument2).GUID;
UIntPtr sendMessageResult = UIntPtr.Zero;
uint aMssg = RegisterWindowMessage("WM_HTML_GETOBJECT");
SendMessageTimeout(theHwnd, aMssg, UIntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, out sendMessageResult);
if(sendMessageResult != UIntPtr.Zero)
{[/SIZE]
[SIZE=2] mshtml.IHTMLDocument2 aHtmlDoc= [/SIZE]
[SIZE=2] (mshtml.IHTMLDocument2)ObjectFromLresult[/SIZE]
[SIZE=2] (sendMessageResult, IID_IHTMLDocument, IntPtr.Zero);
[/SIZE]
Unknown:
Code:
IServiceProvider aSp = (IServiceProvider)aHtmlDoc.parentWindow;
Guid aGUID_BrsApp = typeof(IWebBrowserApp).GUID;
Guid aGUID_WebBrs = typeof(IWebBrowser2).GUID;
object aObj;
try
{
aSp.QueryService(ref aGUID_BrsApp, ref aGUID_WebBrs, out aObj);
aWB = (IWebBrowser2)aObj;
}//try
catch(Exception e)
{
int err = Marshal.GetLastWin32Error();
}//catch
return aWB;
}//if
else
return null;
}//GetIEObjFromHnd
In particular, I'm struggling with the typeof(mshtml.IHTMLDocument2).GUID equivalent, and the declaration of what looks like IServiceProvider at the top.
Many thanks in advance.