Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created March 21, 2014 00:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumatti1/9676753 to your computer and use it in GitHub Desktop.
Save kumatti1/9676753 to your computer and use it in GitHub Desktop.
IEで同期オブジェクト
Option Explicit
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As LongPtr
bInheritHandle As Long
End Type
Private Declare Function MsgWaitForMultipleObjects Lib "user32" _
(ByVal nCount As Long, pHandles As Long, _
ByVal fWaitAll As Long, ByVal dwMilliseconds As Long, _
ByVal dwWakeMask As Long) As Long
Const QS_ALLINPUT = &HFF
Const INFINITE = &HFFFFFFFF
Const WAIT_OBJECT_0 = &H0&
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare PtrSafe Function CreateEvent Lib "kernel32" Alias "CreateEventA" (lpEventAttributes As SECURITY_ATTRIBUTES, ByVal bManualReset As Long, ByVal bInitialState As Long, ByVal lpName As String) As LongPtr
Private Declare PtrSafe Function SetEvent Lib "kernel32" (ByVal hEvent As LongPtr) As Long
Private WithEvents ie As SHDocVw.InternetExplorer
Private hEvent As LongPtr
Private Sub UserForm_Initialize()
Dim st As SECURITY_ATTRIBUTES
hEvent = CreateEvent(st, 0, 0, vbNullString)
If hEvent = 0 Then Exit Sub
Dim pUnk As hoge.InternetExplorerManager
Set pUnk = New InternetExplorerManager
Dim hr As Long
Dim u As UUID
hr = hoge.IIDFromString(hoge.IID_IWebBrowser2, u)
Set ie = pUnk.CreateObject(1, vbNullString, u)
ie.Visible = True
ie.navigate "https://www.google.co.jp/"
Do While MsgWaitForMultipleObjects(1, hEvent, 0, _
INFINITE, QS_ALLINPUT) = WAIT_OBJECT_0 + 1
DoEvents
Loop
CloseHandle hEvent
Debug.Print "呼び出し元"
End Sub
Private Sub ie_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Debug.Print "DocumentComplete"
SetEvent hEvent
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment