Error when calling ComObjCreate

Ask for help, how to use AHK_H, etc.
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Error when calling ComObjCreate

23 Feb 2020, 13:18

Hi, I'm trying to run a main script function from ahkthread. It works well until ComObjCreate function is called which triggers 0x8001010D Error - An outgoing call cannot be made since the application is dispatching an input-synchronous call.
What am I doing wrong? Any solution?
Thanks.

Code: Select all

string:="
(
	Send(""Outlook"")
	return

	Send(Text){
		DllCall(A_AhkExe() ""\ahkFunction"",""Str"",""SendFunc"",""Str"",Text)
		return
	}
	A_AhkExe(){
		static e,i:=VarSetCapacity(e,520),i1:=DllCall(""GetModuleFileName"",PTR,0,Str,e,UInt,260), i2:=VarSetCapacity(e,-1)
		return e
	}
)"

dll0:=ahkthread(string)
return

SendFunc(Text){
	msgbox % Text
	m:=ComObjCreate("Outlook.Application").CreateItem(0)
return
}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Error when calling ComObjCreate

23 Feb 2020, 15:52

This is by design in Windows, google the error + multi threading.
You will need to use postfunction or settimer.
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: Error when calling ComObjCreate

23 Feb 2020, 16:54

Thanks for a quick response. Could you give me an idea? What do you mean by postfunction or settimer?
Thanks.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Error when calling ComObjCreate

23 Feb 2020, 17:47

Simply replace ahkFunction with ahkPostFunction.
Here is the example using DynaCall:

Code: Select all

string:="
(
    Send:=DynaCall(A_AhkPath ""\ahkPostFunction"",[""i=sssssssssss"",2],""SendFunc"")
	Send[""Outlook""]
	return
)"

dll0:=ahkthread(string)
While dll0.ahkReady()
    Sleep 100
return

SendFunc(Text){
	msgbox % Text
	m:=ComObjCreate("Outlook.Application").CreateItem(0)
    return
}
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: Error when calling ComObjCreate

24 Feb 2020, 03:23

Thank you very much HotKeyIt. Few more questions please: :-)
- Do you recommend using DynaCall instead of my DllCall/A_AhkExe? Any disadvantage or potential issue?
- How is it possible to send multiple function parameters (Text1, Text2, Text3)? Example?
- What is the meaning of i=sssssssss part?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Error when calling ComObjCreate

24 Feb 2020, 18:40

Dynacall makes the code shorter, easier to use and faster.

Code: Select all

string:="
(
    Send:=DynaCall(A_AhkPath ""\ahkPostFunction"",[""i=sssssssssss"",2,3,4,5,6,7,8,9,10,11],""SendFunc"")
	Send[""Outlook"",""more"",""params""]
	return
)"

dll0:=ahkthread(string)
While dll0.ahkReady()
    Sleep 100
return

SendFunc(t1,t2,t3){
	msgbox % t1 "`n" t2 "`n" t3
	m:=ComObjCreate("Outlook.Application").CreateItem(0)
    return
}
i=sssssssssss is equivalent to DllCall(func,Str,,Str,,Str,,Str,,Str,,Str,,Str,,Str,,Str,,Str,,Str,Int) see DynaCall.
The other part, 2,3,4,5... is the changed order of parameters when calling the function
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: Error when calling ComObjCreate

25 Feb 2020, 06:07

Thanks HotKeyIt, much appreciated!
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: Error when calling ComObjCreate

06 May 2020, 13:52

Hi HotKeyIt, after a while I have noticed that AhkPostFunction is not working for me in all cases - I'm getting freezes in some scenarios.

As an alternative you mentioned SetTimer - would it be possible to demonstrate this solution? Thanks.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Error when calling ComObjCreate

06 May 2020, 15:38

Code: Select all

string:="
(
  exe:=AhkExported()
  ,exe.ahkassign(""t1"",""Outlook"")
  ,exe.ahkassign(""t2"",""more"")
  ,exe.ahkassign(""t3"",""params"")
  ,exe.ahkExec(""SetTimer, Timer, -100"")
)"

dll0:=ahkthread(string)
While dll0.ahkReady()
    Sleep 100
return

Timer:
	msgbox % t1 "`n" t2 "`n" t3
	m:=ComObjCreate("Outlook.Application").CreateItem(0)
return
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: Error when calling ComObjCreate

08 May 2020, 11:37

Thank you very much!

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 23 guests