<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11536&amp;type=atom" />
	<updated>2016-05-02T21:26:25Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11536</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103289#p103289" />
			<content type="html"><![CDATA[<p>Если нужно, вызвать функцию из DLL на C#, то можно переделать саму DLL и все будет работать. Я проверила, AutoHotkey вызывает функцию. <br />вот инструкция: <a href="http://jonxxx.me/13-metatrader/15-eksport-funktsij-iz-net-dll-c-dllexport-net-framework-v-metatrader">http://jonxxx.me/13-metatrader/15-ekspo … metatrader</a></p>]]></content>
			<author>
				<name><![CDATA[Elena]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32567</uri>
			</author>
			<updated>2016-05-02T21:26:25Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103289#p103289</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103149#p103149" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>В первом примере у вас путаница с названиями: при компиляции testD<span style="color: red">D</span>L, при обращении — testD<span style="color: red">L</span>L.</p></blockquote></div><p>Это опечатка тут на форуме (уже исправила), я просто руками команды набирала и ошиблась, а так у меня все компилируется автоматически и имена фалов тоже автоматом вставляются.</p><div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>А битности dll и автохотки совпадают?</p></blockquote></div><p>Да это обязательно иначе не заработает.</p><p>Вот рабочее решение:<br />Файл <strong>testDLL.cpp</strong> будущей .dll:<br /></p><div class="codebox"><pre><code>
#include &lt;stdio.h&gt;

#define DLLEXPORT __declspec(dllexport)
#define DLLIMPORT __declspec(dllimport)

#ifdef __cplusplus
extern &quot;C&quot; {
#endif

    DLLEXPORT long int testfunc(long int a, long int b)
    {
        return a + b;
    }

#ifdef __cplusplus
}
#endif
</code></pre></div><p>Вот содержимое кода AutoHotkey:<br /></p><div class="codebox"><pre><code>
; --- тест вызова dll (кнопка поиск на мультимедиа клаве) ---
Browser_Search::
    Result := DllCall(&quot;testDLL.dll\testfunc&quot;, &quot;Int&quot;, 10, &quot;Int&quot;, 20 ,&quot;CDecl&quot;)
    MsgBox, DLL вернула значение: %Result% , ErrorLevel: %ErrorLevel%
return
</code></pre></div><p>Результат работы с C# библиотекой, на выходе имеем:<br /><strong>DLL вернула значение:&nbsp; 30, ErrorLevel: 0</strong></p><p>Слава богу, заработало! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[Elena]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32567</uri>
			</author>
			<updated>2016-04-27T20:34:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103149#p103149</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103147#p103147" />
			<content type="html"><![CDATA[<p>А битности dll и автохотки совпадают?</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-04-27T20:10:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103147#p103147</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103145#p103145" />
			<content type="html"><![CDATA[<p>В первом примере у вас путаница с названиями: при компиляции testD<span style="color: red">D</span>L, при обращении — testD<span style="color: red">L</span>L.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-04-27T19:52:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103145#p103145</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103143#p103143" />
			<content type="html"><![CDATA[<p><strong>Malcev</strong>, приведенную инструкцию читала когда писала код, там все понятно. Там есть пример вызова функции из самого AutoHotkey, <strong>но</strong> нет примера как написать самому функцию в Dll библиотеке.<br />Коды ошибок приведены в тексте, я их пояснила.</p>]]></content>
			<author>
				<name><![CDATA[Elena]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32567</uri>
			</author>
			<updated>2016-04-27T19:30:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103143#p103143</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103139#p103139" />
			<content type="html"><![CDATA[<p><a href="https://autohotkey.com/docs/commands/DllCall.htm">https://autohotkey.com/docs/commands/DllCall.htm</a><br /></p><div class="quotebox"><blockquote><p>-3: The specified DllFile could not be accessed or loaded. If no explicit path was specified for DllFile, the file must exist in the system&#039;s PATH or A_WorkingDir. This error might also occur if the user lacks permission to access the file, or if AutoHotkey is 32-bit and the DLL is 64-bit or vice versa.</p><p>-4: The specified function could not be found inside the DLL.</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-04-27T19:12:05Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103139#p103139</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103138#p103138" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong> В первом случаи AutoHotkey вообще<strong> не</strong> видит Dll, во втором случаи он <strong>видит </strong>Dll но <strong>не </strong>может в ней найти функцию. Dll лежит в той же папке что и сам AutoHotkey, поэтому все должно работать без указания путей.<br />Есть подозрение что в исходные с++ и C# файлы нужно что-то добавить чтобы получились полноценные библиотеки. Что именно пока не знаю.</p>]]></content>
			<author>
				<name><![CDATA[Elena]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32567</uri>
			</author>
			<updated>2016-04-27T19:12:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103138#p103138</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103137#p103137" />
			<content type="html"><![CDATA[<p>Может быть LoadLibrary сначала, или путь к длл указывать полные.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2016-04-27T19:05:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103137#p103137</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103135#p103135" />
			<content type="html"><![CDATA[<p>Вот вариант кода для C# библиотеки:<br /></p><div class="codebox"><pre><code>
using System;
public class ClassFunc
{
    public int testfunc(int a, int b)
    {
        return a + b;
    }
}
</code></pre></div><p>Команда для компиляции этого файла:<br /><strong>csc.exe /t:library /out:testDLL.dll testDLL.cs</strong></p><p>AutoHotkey видит библиотеку но не может найти в ней функцию<br />Результат работы с C# библиотекой, на выходе имеем:<br /><strong>DLL вернула значение:&nbsp; , ErrorLevel: -4</strong></p><p>ErrorLevel: -4: это значит указанная функция не найдена в DLL.</p><p>Пробовала варианты, ни один из вариантов не работает:<br /></p><div class="codebox"><pre><code>
Result := DllCall(&quot;testDLL.dll\testfunc&quot;, &quot;Int&quot;, 10, &quot;Int&quot;, 20)
Result := DllCall(&quot;testDLL.dll\ClassFunc.testfunc&quot;, &quot;Int&quot;, 10, &quot;Int&quot;, 20)
Result := DllCall(&quot;testDLL.dll\ClassFunc\testfunc&quot;, &quot;Int&quot;, 10, &quot;Int&quot;, 20)
</code></pre></div><p>Что нужно поменять чтобы AutoHotkey смог вызвать функцию из C# библиотеки?</p>]]></content>
			<author>
				<name><![CDATA[Elena]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32567</uri>
			</author>
			<updated>2016-04-27T18:53:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103135#p103135</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Как создать свою DLL и вызвать ее из AutoHotkey]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103126#p103126" />
			<content type="html"><![CDATA[<p>Не получается вызвать свою функцию (функция в своей .dll) из AutoHotkey <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" />.</p><p>Вот файл <strong>testDLL.cpp</strong> будущей .dll:<br /></p><div class="codebox"><pre><code>
#include &lt;stdio.h&gt;

long int testfunc(long int a, long int b)
{
   return a + b;
}
</code></pre></div><p>Компилирую его, в независимую dll библиотеку используя MinGW, следующими командами:<br /><strong>g++.exe -o testDLL.o -c testDLL.cpp<br />g++.exe -static -static-libgcc -static-libstdc++ -shared -o testDLL.dll testDLL.o</strong></p><br /><p>Вот содержимое кода AutoHotkey:<br /></p><div class="codebox"><pre><code>
; --- тест вызова dll (кнопка поиск на мультимедиа клаве) ---
Browser_Search::
    Result := DllCall(&quot;testDLL.dll\testfunc&quot;, &quot;Int&quot;, 10, &quot;Int&quot;, 20)
    MsgBox, DLL вернула значение: %Result% , ErrorLevel: %ErrorLevel%
return
</code></pre></div><p>В результате всего этого на выходе имеем:<br /><strong>DLL вернула значение:&nbsp; , ErrorLevel: -3</strong></p><p>ErrorLevel: -3: это значит невозможно обратиться к указанному DllFile.</p><p>Пробовала убрать из .cpp файла аргументы функции <strong>testfunc </strong>и просто сделать <strong>return 1;</strong> и соответственно вызывать DLL без параметров - это тоже не помогает. Dll лежит в той же директории что и сам AutoHotkey.</p><p>Кто уже писал свои .dll? Подскажите что я делаю не так и что нужно чтобы вызвать функцию из своей .dll?<br />Всем спасибо кто откликнется <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" />.</p>]]></content>
			<author>
				<name><![CDATA[Elena]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32567</uri>
			</author>
			<updated>2016-04-27T17:03:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103126#p103126</id>
		</entry>
</feed>
