<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11927&amp;type=atom" />
	<updated>2016-08-21T03:38:19Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11927</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106946#p106946" />
			<content type="html"><![CDATA[<p>StrLen тоже только до 0 меряет. Так что всё там есть. А убрав &quot;cp0&quot;, вы поменяли кодировку чтения на Юникод, и этот нулевой байт стал восприниматься как часть кода символа. Т.е. строка у вас в кодировке ANSI, а вы её читаете как юникодную. Короче, петрушка получается. Если из DLL выдаётся не осмысленный текст, а набор байтов, то проще с ним работать в переменной StrOut, нет смысла его читать в другую.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2016-08-21T03:38:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106946#p106946</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106939#p106939" />
			<content type="html"><![CDATA[<p><strong>YMP</strong> ее там нет, длина&nbsp; ХЭШ суммы StrLen(OutText) меньше чем Result.</p><p>Что бы она там появиласть пришлось поменять одну строку присвоения значения, убрала&nbsp; &quot;CP0&quot;:<br /></p><div class="codebox"><pre><code>OutText := StrGet(ptr_StrOut, Result)</code></pre></div><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-08-20T17:06:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106939#p106939</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106937#p106937" />
			<content type="html"><![CDATA[<p>Она там и будет. Но MsgBox не воспроизведёт то, что идёт после 0.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2016-08-20T16:22:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106937#p106937</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106934#p106934" />
			<content type="html"><![CDATA[<p><strong>YMP</strong> речь об одной строке которую возвращает функция из DLL.<br />Алгоритм следующий есть исходная строка <strong>StrIn</strong> ее и ее длину <strong>StrLen(StrIn</strong>) передаем в функцию из DLL, назад получаем ХЭШ этой строки в переменную <strong>StrOut</strong>, также функция из DLL вернет длину этой ХЭШ строки в переменную <strong>Result</strong>.</p><p>В переменной <strong>StrOut</strong> могут быть произвольные символы в том числе и 00:HEX.</p><p>Я реализую алгоритм подсчета SHA-3 <a href="https://ru.wikipedia.org/wiki/SHA-3">https://ru.wikipedia.org/wiki/SHA-3</a><br />мне внутри переменной <strong>StrOut</strong> нужна ХЭШ сумма.</p><p>Как мне получить полностью эту ХЭШ сумму?</p>]]></content>
			<author>
				<name><![CDATA[Elena]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32567</uri>
			</author>
			<updated>2016-08-20T15:50:05Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106934#p106934</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106931#p106931" />
			<content type="html"><![CDATA[<p>Ну, вообще-то 0 — это конец строки. Так что всё законно. Поэтому уточните, речь о строке или о нескольких строках?</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2016-08-20T15:06:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106931#p106931</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106929#p106929" />
			<content type="html"><![CDATA[<p><strong>YMP</strong> Есть мини проблема, код работает пока в выходном потоке в переменной <strong>StrOut</strong> нет символа с кодом 00:HEX (это нулевой символ). Вот пример в HEX:<br />33 dc 44 21 00 33 1b 35 - так должно быть<br />33 dc 44 21&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- так получается (обрывается на нулевом символе)</p><p>Менять кодировку с &quot;cp0&quot; на что-то другое результата не дает. <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /><br />Как сделать чтобы все символы записались в <strong>StrOut</strong> и даже нулевой?</p>]]></content>
			<author>
				<name><![CDATA[Elena]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32567</uri>
			</author>
			<updated>2016-08-20T14:36:56Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106929#p106929</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106920#p106920" />
			<content type="html"><![CDATA[<p><strong>YMP</strong> Спасибо, код заработал. <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-08-20T10:25:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106920#p106920</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106917#p106917" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>
; ---- исходные данные ----
StrIn := &quot;AbCdEfGh&quot;        ; исходная строка которую нужно передать в DLL функцию
ptr_StrIn := &amp;StrIn        ; указатель на строку StrIn
VarSetCapacity(StrOut, 20) ; переменная куда поместим результат после вызова DLL, для нее зарезервировали 20 байт
ptr_StrOut := &amp;StrOut      ; указатель на строку StrOut

Result := DllCall(&quot;test.dll\testfunc&quot;, &quot;astr&quot;, StrIn,  UInt64, StrLen(StrIn),  &quot;ptr&quot;, ptr_StrOut, &quot;CDecl&quot;)

OutText := StrGet(ptr_StrOut, Result, &quot;cp0&quot;)

MsgBox, DLL вернула значение: %Result% , ErrorLevel: %ErrorLevel% , значение StrOut после вызова: %OutText%
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2016-08-20T06:38:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106917#p106917</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Как передать строку в DllCall по ссылке и получить строку назад]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106913#p106913" />
			<content type="html"><![CDATA[<p>Есть переменная со строкой, ее нужно передать внутрь функции из DLL библиотеки и назад из этой же DLL нужно получить строку. Передачу <strong>желательно</strong> делать по ссылке, но если это сложно то можно просто передать саму строку.</p><p>Исходная строка что передали внутрь DLL приходит какая-то кривая, при вызове <strong>MessageBox </strong>из DLL выводится белеберда.<br />Результат что возвращает DLL значение 8 - это длина строки, она верная, ErrorLevel = 0 - значит все отработало нормально, но вот значение <strong>StrOut </strong>после вызова пустое, там ничего нет. <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /></p><p>Помогите разобрать что нужно поправить чтобы все заработало, чтобы строка принималась и записывалась в <strong>StrOut </strong>. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p><p>код AutoHotkey:<br /></p><div class="codebox"><pre><code>
; ---- исходные данные ----
StrIn := &quot;AbCdEfGh&quot;        ; исходная строка которую нужно передать в DLL функцию
ptr_StrIn := &amp;StrIn        ; указатель на строку StrIn
VarSetCapacity(StrOut, 20) ; переменная куда поместим результат после вызова DLL, для нее зарезервировали 20 байт
ptr_StrOut := &amp;StrOut      ; указатель на строку StrOut

Result := DllCall(&quot;test.dll\testfunc&quot;, StrP, ptr_StrIn,  UInt64, StrLen(StrIn),  StrP, ptr_StrOut, &quot;CDecl&quot;)

MsgBox, DLL вернула значение: %Result% , ErrorLevel: %ErrorLevel% , значение StrOut после вызова: %StrOut%
</code></pre></div><p>код функции в DLL (test.c - исходник на C++):<br /></p><div class="codebox"><pre><code>
#include &lt;Windows.h&gt; // для MessageBox()

long int testfunc(const unsigned char *in, unsigned long long int inLen, unsigned char *out)
{
    char str[20] = &quot;&quot;;
    for(unsigned long long int i = 0; i &lt; inLen; i++)
    {
        out[i] = in[i];
        str[i] = in[i];
    }
    MessageBox(NULL, str, &quot;String In&quot;, MB_OK);
    return inLen;
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Elena]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32567</uri>
			</author>
			<updated>2016-08-19T20:56:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106913#p106913</id>
		</entry>
</feed>
