Page 1 of 1

IPC: C# --> AHK

Posted: 04 Jan 2017, 13:43
by Verdlin
I've created a simple C# dll which I'm trying to leverage with AHK. There are more than enough IPC: AHK --> AHK examples. I have yet to find a C# --> AHK example.

I'm open to suggestions, but would rather one of these methods:
  1. Register callback so that AHK code invokes upon C# function invoke
  2. Named pipe server. C# sends messages to listening AHK app
Can anyone help me get started? Note: I'm using CLR, and I can invoke whatever methods I want within the C# dll, I just can't figure out how to pass data between the dll and AHK.

Re: IPC: C# --> AHK

Posted: 04 Jan 2017, 13:46
by guest3456
see the example on this help page:
https://autohotkey.com/docs/commands/OnMessage.htm

Re: IPC: C# --> AHK  Topic is solved

Posted: 04 Jan 2017, 22:12
by lexikos
Is this C# dll loaded into your script, or loaded into a separate process? "IPC" usually means inter-process communication, which means communication between two or more processes.

I would suggest using an object/class.

If you need to communicate with another process, you can use ObjRegisterActive in the script and Marshal.GetActiveObject from C#.

If the dll is loaded into the script, you can just pass the object as a value to the dll. Depending on the version of C#, I suppose you can use the dynamic type and interact with the object (call methods or properties) using natural C# syntax.

Re: IPC: C# --> AHK

Posted: 05 Jan 2017, 16:00
by Verdlin
lexikos wrote:Is this C# dll loaded into your script, or loaded into a separate process? "IPC" usually means inter-process communication, which means communication between two or more processes.

I would suggest using an object/class.

If you need to communicate with another process, you can use ObjRegisterActive in the script and Marshal.GetActiveObject from C#.

If the dll is loaded into the script, you can just pass the object as a value to the dll. Depending on the version of C#, I suppose you can use the dynamic type and interact with the object (call methods or properties) using natural C# syntax.
Thanks, Lexikos. Very helpful! I realized I was only trying to forward events and that you showed us how to forward events from C# to AHK in the "Event Handling" post. This is working wonderfully!