C# with AHK_H

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
User avatar
manehscripts
Posts: 126
Joined: 03 May 2019, 16:10

C# with AHK_H

31 Jan 2021, 22:36

Hi guys,

I'm try include AutoHotkey.dll in my C# project. I'm using AutoHotkey.Interop https://github.com/amazing-andrew/AutoHotkey.Interop, but my Autohotkey.dll was compiled by me and I would like to know where I change the dlls.
I'm trying to run the LoadFile ahk.LoadFile("test.ahk"); with the code below. The AhkThread.ahk file is in the correct folder and works when I open test.ahk outside of Visual Studio.
I already changed all AutoHotkey.dll in the AutoHotkey.Interop folder by my compiled AutoHotkey.dll and even then the error continues.

Code: Select all

; FILE Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AutoHotkey.Interop;

namespace ahk
{
    class Program
    {
        static void Main(string[] args)
        {
            //grab a copy of the AutoHotkey singleton instance
            var ahk = AutoHotkeyEngine.Instance;

            //Load a library or exec scripts in a file
            ahk.LoadFile("test.ahk");
        }
    }
}

Code: Select all

; FILE test.ahk

#NoTrayIcon
#SingleInstance, Force
share:=CriticalObject({count:0,s1Thread:"",s2Thread:""})
s1Script := "
(
	#NoTrayIcon
	share:=CriticalObject(" (&share) ")
	Loop,
    {
        Count := ++share.count
		ToolTip, s1 count: `%Count`%
    }
)"
s2Script := "
(
	#NoTrayIcon
	share:=CriticalObject(" (&share) ")
	Loop,
    {
        if share.s1Thread.ahkReady() {
            Count := share.count
            MsgBox, Count s1: `%Count`%
        } else {
            MsgBox, Count s1: STOPPED
        }
    }
)"

Gui, Add, Checkbox, h50 w400 vs1 gs1G, START COUNT WITH s1
Gui, Add, Button, h50 w400 vs2 gs2G, CHECK s1 WITH s2
Gui, Show, `t
return

;s1
;===============
s1G:
    if (toggles1 := !toggles1) {
        if !share.s1Thread.ahkReady() {
            SoundBeep, 4000
            share.s1Thread := AhkThread(s1Script)
        }
    } else {
        if share.s1Thread.ahkReady() {
            SoundBeep, 8000
            share.s1Thread.ahkTerminate()
        }
		share.count:=0
	}
return

;s2
;===============
s2G: 
    if (toggles2 := !toggles2) {
		GuiControl, , s2, STOP CHECK s1 WITH s2
        if !share.s2Thread.ahkReady() {
            SoundBeep, 4000
            share.s2Thread := AhkThread(s2Script)
        }
    } else {
        if share.s2Thread.ahkReady() {
            SoundBeep, 8000
            share.s2Thread.ahkTerminate()
        }
        GuiControl,, s2, CHECK s1 WITH s2
    }
return

GuiClose:
	if share.s1Thread.ahkReady() {
		SoundBeep, 8000
		share.s1Thread.ahkTerminate()
	}
	if share.s2Thread.ahkReady() {
		SoundBeep, 8000
		share.s2Thread.ahkTerminate()
	}
ExitApp

Error:
ahk.png
ahk.png (35.93 KiB) Viewed 6161 times
-----------------------------------------------------------
Stop to think, shut up to resist, and act to win!
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: C# with AHK_H

01 Feb 2021, 00:07

To be able to use AhkThread from AutoHotkey.dll you will need to include AutoHotkey.dll in RCData of your executable as F903E44B8A904483A1732BA84EA6191F!
User avatar
manehscripts
Posts: 126
Joined: 03 May 2019, 16:10

Re: C# with AHK_H

01 Feb 2021, 03:14

HotKeyIt wrote:
01 Feb 2021, 00:07
To be able to use AhkThread from AutoHotkey.dll you will need to include AutoHotkey.dll in RCData of your executable as F903E44B8A904483A1732BA84EA6191F!
Thanks, but could you guide me how to perform this process? Does it have anything to do with CleanUpAndPack.ahk ?
-----------------------------------------------------------
Stop to think, shut up to resist, and act to win!
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: C# with AHK_H

01 Feb 2021, 05:42

Yes but CleanUpAndPack acts on the exe, not dll.
You can use ResourceHacker to add dll to RCDATA in your executable.

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 17 guests