how to dll Inject Topic is solved

Ask for help, how to use AHK_H, etc.
HotKeyIt
Posts: 1549
Joined: 29 Sep 2013, 18:35
Contact:

Re: how to dll Inject

24 Aug 2017, 16:26

The problem is that you don't change the GWL_WNDPROC back to pWndProcOld, so when dll exits the function is dead and obviously can't be executed.
Add following code before freeing the rThread variable and you will see it does not crash:

Code: [Select all] [Download] GeSHi © Codebox Plus

vScript = ;continuation section
(
DllCall("SetWindowLong%vSfx%", Ptr,hWnd, Int,-4, Ptr,pWndProcOld, Ptr) ;GWL_WNDPROC := -4
)
rThread.Exec(vScript)


If you don't want to unload the dll, simply remove __Delete key in base or set it empty or set base empty before freeing rThread:
rThread.base.Remove("__Delete") or
rThread.base.__Delete:="" or
rThread.base:=""
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how to dll Inject

20 Sep 2017, 15:12

Thanks again for your help HotKeyIt.

I've written a variant of InjectAhkDll which does not require _Struct.ahk, this means that if you copy and paste the function to the bottom of your script, all you need to run it is the appropriate dll file.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how to dll Inject

02 Oct 2017, 21:35

How can you communicate from the remote thread to the original script e.g. pass data (a number). I had problems with PostMessage/SendMessage, and I had problems with GetProp and SetProp.

I'm working on this, I believe it's working apart from passing the hFont from the remote thread (in an AutoHotkey instance) to the original script:
MsgBox/InputBox gets hidden under another window (+ InputBox custom font) - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28130&p=166471#p166471

This GetProp/SetProp example worked between two scripts launched normally. But I had trouble trying to do this with a remote thread.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

HotKeyIt
Posts: 1549
Joined: 29 Sep 2013, 18:35
Contact:

Re: how to dll Inject

03 Oct 2017, 03:16

What is the error you get?
MSDN wrote:SetProp is subject to the restrictions of User Interface Privilege Isolation (UIPI). A process can only call this function on a window belonging to a process of lesser or equal integrity level. When UIPI blocks property changes, GetLastError will return 5.
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how to dll Inject

03 Oct 2017, 09:59

I didn't get any error. Thanks for the quote, I noticed it at MSDN but I don't know what its significance is, when I tried GetProp between two scripts in the example above it worked fine. I've provided some example code below of trying to do it in a remote thread.

I managed to get PostMessage/SendMessage to work, from remote thread to main script. I suppose that would be the best way to communicate in that direction. (To communicate from main script to remote thread, you just put information into the script string that you execute via Exec.)

Are there any other good methods for communication from remote thread to main script other than XXXProp and XXXMessage? Cheers.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

HotKeyIt
Posts: 1549
Joined: 29 Sep 2013, 18:35
Contact:

Re: how to dll Inject

03 Oct 2017, 12:49

Any IPC should work, pipe, FileMapping, ini ...
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how to dll Inject

03 Oct 2017, 13:01

Hadn't come across the term IPC before, I guess you meant:
Inter-process communication - Wikipedia
https://en.wikipedia.org/wiki/Inter-process_communication

I was curious as to whether, since the script and remote thread are connected in some way, there might be a more direct method. General methods might be a good topic for a new thread.

If anyone can work out why GetProp wasn't working that would be great.

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 1 guest