Page 1 of 1

#If and ComObjCreate return error 0x8001010D

Posted: 04 May 2018, 12:03
by malcev
Why If I press f10 I will get "Error: 0x8001010D - An outgoing call cannot be made since the application is dispatching an input-synchronous call", but if I press f11 all works OK.

Code: Select all

#If test()
f10::
#if

#If test1()
f11::
#if

test()
{
   ComObjCreate("InternetExplorer.Application")
}

test1()
{
   ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
}

Re: #If and ComObjCreate return error 0x8001010D

Posted: 04 May 2018, 12:10
by gregster
Sorry, this code makes no sense at all. What is the expected outcome of this?

Re: #If and ComObjCreate return error 0x8001010D

Posted: 04 May 2018, 12:16
by malcev
I want to know why when I create some com objects inside #If I receive error 0x8001010D.

Re: #If and ComObjCreate return error 0x8001010D

Posted: 04 May 2018, 12:58
by awel20
https://autohotkey.com/docs/commands/_If.htm#General_Remarks wrote:Note: Scripts should not assume that the expression is only evaluated when the key is pressed (see below).

The expression may also be evaluated whenever the program needs to know whether the hotkey is active. For example, the #If expression for a custom combination like a & b:: might be evaluated when the prefix key (a in this example) is pressed, to determine whether it should act as a custom modifier key.
You are creating a new instance of IE every time the expression is evaluated. How long does it take for IE to load-up when you launch it manually? I don't think it can keep up. Try re-thinking your approach to limit the number of times ComObjCreate is called, and be sure to close the objects you create when finished.

Re: #If and ComObjCreate return error 0x8001010D

Posted: 04 May 2018, 14:10
by malcev
Try re-thinking your approach to limit the number of times ComObjCreate is called
I will get error after first run.
How long does it take for IE to load-up when you launch it manually? I don't think it can keep up
Ok, one more example:

Code: Select all

;ComObjError(false)
#If test()
f10::
#if

test()
{
   a := a_tickcount
   ComObjGet("winmgmts:")
   msgbox % a_tickcount - a
}
If I press F10 I will get the error.
If I uncomment ComObjError(false) then I will have 15ms.

Re: #If and ComObjCreate return error 0x8001010D

Posted: 05 May 2018, 00:38
by lexikos
0x8001010D means RPC_E_CANTCALLOUT_ININPUTSYNCCALL: "An outgoing call cannot be made since the application is dispatching an input-synchronous call."

The "input-synchronous call" is from the keyboard/mouse hook thread to the main thread, asking it to evaluate the #if expression.

You can't do it, so just don't.

Re: #If and ComObjCreate return error 0x8001010D

Posted: 05 May 2018, 04:37
by malcev
I see. Could You tell me please, why the result of ACC function is wrong inside #If but there is no error.
You can test it:
1) open google chrome, move cursor to address bar, and press f10, f11.
If we press f10 we will get "New Tab - Google Chrome" (wrong result).
If we press f11 we will get "Address and search bar" (right result).
There is the same behaviour in Firefox.

Code: Select all

#If !test()
f10:: return 
#If
return

f11::test()
return

test()
{
   tooltip % Acc_test(child).accName(child)
}

Acc_test(ByRef _idChild_ = "", x = "", y = "")
{
	Static	h
	If Not	h
		h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
	If	DllCall("oleacc\AccessibleObjectFromPoint", "Int64", x==""||y==""?0*DllCall("GetCursorPos","Int64*",pt)+pt:x&0xFFFFFFFF|y<<32, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
	Return	ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}

Re: #If and ComObjCreate return error 0x8001010D

Posted: 05 May 2018, 05:08
by lexikos
I assume it is unable to get a more specific result for the same reason as the other error: "An outgoing call cannot be made [while] the application is dispatching an input-synchronous call."

Methods of out-of-process COM objects cannot be called while #If is being evaluated.

There is no error message because 1) DllCall in v1 does not show error messages except in critical situations, and 2) nothing happened which could be considered an error condition (DllCall called the function, it did not throw an exception, it unwound the stack correctly and returned a value).