Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save kumatti1/5feb012af58063c6d73e to your computer and use it in GitHub Desktop.

Select an option

Save kumatti1/5feb012af58063c6d73e to your computer and use it in GitHub Desktop.
IUnknown_QueryServiceForWebBrowserApp
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Declare PtrSafe _
Function IIDFromString Lib "ole32.dll" ( _
ByVal lpsz As LongPtr, _
ByRef lpiid As GUID _
) As Long
Private Declare PtrSafe _
Function IUnknown_QueryServiceForWebBrowserApp Lib "shlwapi.dll" Alias "#538" ( _
ByVal punk As IUnknown, _
ByRef riid As GUID, _
ByRef ppv As Any _
) As Long
Const IID_IWebBrowser2 = "{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}"
Sub hoge2()
Const url = "https://www.google.co.jp/?gws_rd=ssl"
Dim IE As Object
Set IE = CreateObject("Shell.Application").Windows.findwindowSW(url, Empty, 1, 0, 1)
If IE Is Nothing Then Exit Sub
Dim hr As Long
Dim iid As GUID
Dim ie2 As Object
hr = IIDFromString(StrPtr(IID_IWebBrowser2), iid)
Dim win2 As Object
Set win2 = IE.document.parentWindow
hr = IUnknown_QueryServiceForWebBrowserApp(win2, iid, ie2)
Debug.Print Hex$(hr), ie2.locationurl
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment