<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3689179</guid>
        <pubDate>Tue, 18 Oct 2016 06:01:48 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3689179</link>
        <description><![CDATA[nik531: Файл может меняться между процедурами чтения файла. GetSize на сколько я понимаю приведёт к обращенbю к HDD. Я кончно не замерял. но что мешает корпарции зла сделать такую подляну в будущих версиях. Пока работает так отсавлю. Если кто проверит на сколько быстро выполнятся GetFileEx. Буду благодарен. А файл там большие до 20 гигобайт. и читаются блоками о 512 кило байт.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688649</guid>
        <pubDate>Fri, 14 Oct 2016 08:30:58 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688649</link>
        <description><![CDATA[leo: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688627'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-14T03:06:40+00:00">14.10.16, 03:06</time></span><div class='quote '>Мне кажется это замедлит работу</div></div><br>
Если размер файла при чтении не изменяется, то GetFileSize достаточно вызвать 1 раз. Соотв-но, затраты времени на этот вызов будут мизерными по сравнению с открытием и чтением самого файла.]]></description>
        <author>leo</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688640</guid>
        <pubDate>Fri, 14 Oct 2016 07:32:57 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688640</link>
        <description><![CDATA[Pacific: <strong class='tag-b'>nik531</strong><br>
У вас какое-то странное представление о быстродействии. Проверка &quot;if (offset &lt; size)&quot; в миллион раз быстрее, чем чтение данных с диска (обычного, HDD). Уж если работа с диском так критична, то проще вложиться в какой-нибудь SSD для PCI-Express слота, который точно позволит упереться в CPU. А потом только оптимизировать код чтения файла.]]></description>
        <author>Pacific</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688627</guid>
        <pubDate>Fri, 14 Oct 2016 03:06:40 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688627</link>
        <description><![CDATA[nik531: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688574'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>leo &#064; <time class="tag-quote__quoted-time" datetime="2016-10-13T16:32:48+00:00">13.10.16, 16:32</time></span><div class='quote '>Может проще делать проверку самому до вызова ReadFileEx? Всё равно же Offset для чтения &quot;ручками&quot; задаешь - что мешает добавить сравнение с GetFileSize?</div></div><br>
Мне кажется это замедлит работу. А быстро действие в этом проекте критично.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688574</guid>
        <pubDate>Thu, 13 Oct 2016 16:32:48 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688574</link>
        <description><![CDATA[leo: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688473'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-13T02:23:30+00:00">13.10.16, 02:23</time></span><div class='quote '>И получается нет возможности как раньше узнать достигнут ли конец файла в момент вызова ReadFileEx.<br>
И теперь прейдёться проверять коды ошибок в двух местах.</div></div><br>
Может проще делать проверку самому до вызова ReadFileEx? Всё равно же Offset для чтения &quot;ручками&quot; задаешь - что мешает добавить сравнение с GetFileSize?]]></description>
        <author>leo</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688554</guid>
        <pubDate>Thu, 13 Oct 2016 12:54:50 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688554</link>
        <description><![CDATA[Cfon: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688504'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-13T08:14:53+00:00">13.10.16, 08:14</time></span><div class='quote '>если базовая функция такая как работа с файлом меняет свое поведение в новой версии ОС это зло. А корпорация которая это делает корпорация зла. что тут сложного ?<br>
при чём тут руки.</div></div><br>
значит надо выпрямить руки сотрудникам Мелкософта так?  :D <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2016-10-13T12:56:16+00:00">13.10.16, 12:56</time></span></span><br>
хотя скорее ты прав там же индусы работают с кривыми руками :D]]></description>
        <author>Cfon</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688504</guid>
        <pubDate>Thu, 13 Oct 2016 08:14:53 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688504</link>
        <description><![CDATA[nik531: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688479'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Cfon &#064; <time class="tag-quote__quoted-time" datetime="2016-10-13T05:21:07+00:00">13.10.16, 05:21</time></span><div class='quote '>сам ты зло, руки выпрями сначала, а потом бросай критику того чего ты даже близко не понимаешь</div></div><br>
если базовая функция такая как работа с файлом меняет свое поведение в новой версии ОС это зло. А корпорация которая это делает корпорация зла. что тут сложного ?<br>
при чём тут руки.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688479</guid>
        <pubDate>Thu, 13 Oct 2016 05:21:07 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688479</link>
        <description><![CDATA[Cfon: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688473'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-13T02:23:30+00:00">13.10.16, 02:23</time></span><div class='quote '>И это весьма печальное изменение внесённое корпорацией зла.</div></div><br>
сам ты зло, руки выпрями сначала, а потом бросай критику того чего ты даже близко не понимаешь :D]]></description>
        <author>Cfon</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688478</guid>
        <pubDate>Thu, 13 Oct 2016 05:07:53 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688478</link>
        <description><![CDATA[Pacific: <strong class='tag-b'>nik531</strong><br>
Нет, если очень хочется использовать именно GetOverlappedResult, то нужно в lpOverlapped прописать hEvent. Для каждой отдельной lpOverlapped - свой hEvent. Но надежнее ждать именно IOCompletionRoutine, и там выставлять свой флаг &quot;можно запускать следующую операцию&quot;. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2016-10-13T05:18:10+00:00">13.10.16, 05:18</time></span></span><br>
Я бы вообще использовал IOCP - <a class='tag-url' href='https://msdn.microsoft.com/en-us/library/windows/desktop/aa365198(v=vs.85).aspx' target='_blank'>https://msdn.microsoft.com/en-us/library/wi...8(v=vs.85).aspx</a><br>
GetQueuedCompletionStatus работает надёжно.]]></description>
        <author>Pacific</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688473</guid>
        <pubDate>Thu, 13 Oct 2016 02:23:30 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688473</link>
        <description><![CDATA[nik531: так это получается синхронное чтение тогда. <br>И получается нет возможности как раньше узнать достигнут ли конец файла в момент вызова ReadFileEx. И это весьма печальное изменение внесённое корпорацией зла. <br>И теперь прейдёться проверять коды ошибок в двух местах. Код ошибки ReadFileEx и код в вызове overloped callback. Что на мой взгляд выглядит как костыли. <br>И я правильно понимаю это единственное правильное решение для организации асинхронного чтения файла. И GetOverlappedResult совершенно без полезна в этой ситуации надо всё равно ждать вызова Callback.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688389</guid>
        <pubDate>Wed, 12 Oct 2016 11:22:30 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688389</link>
        <description><![CDATA[Pacific: Разобрался. В MSDN про GetOverlappedResult написано:<br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '>If the hEvent member of the OVERLAPPED structure is NULL, <strong class='tag-b'>the system uses the state of the hFile handle</strong> to signal when the operation has been completed. <strong class='tag-b'>Use of file</strong>, named pipe, or communications-device handles for this purpose is <strong class='tag-b'>discouraged</strong>. It is safer to use an event object because of the confusion that can occur when multiple simultaneous overlapped operations are performed on the same file, named pipe, or communications device. In this situation, <strong class='tag-b'>there is no way to know which operation caused the object&#39;s state to be signaled</strong>.</div></div><br>
Как раз твой случай. GetOverlappedResult иногда получает результат от предыдущей операции, а не от текущей, так как файловый хэндл у нас один, а операций много в цикле выполняется. Похоже на типичную гонку между двумя потоками: статус у хэндла остался ERROR_HANDLE_EOF от предыдущей операции, код в ядре еще не успел его поменять на STATUS_PENDING, а ты уже его проверяешь, вызывая GetOverlappedResult.<br>
<br>
Исправленный код:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#include &quot;stdafx.h&quot;</div><div class="code_line">#include &#60;windows.h&#62;</div><div class="code_line">#include &#60;stdio.h&#62;</div><div class="code_line">#define BUFSIZE 4096</div><div class="code_line">&nbsp;</div><div class="code_line">VOID CALLBACK __IOCompletionRoutine(DWORD dwErrorCode, DWORD dwSize, LPOVERLAPPED lpOverlapped)</div><div class="code_line">{</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">int _tmain(int argc, _TCHAR* argv[])</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;HANDLE m_hFile = CreateFileW(</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;L&quot;test.test&quot;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ | GENERIC_WRITE,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_SHARE_READ,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;NULL,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_ATTRIBUTE_NORMAL |</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_NO_BUFFERING |</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_OVERLAPPED |</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_WRITE_THROUGH |</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_RANDOM_ACCESS,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;NULL</div><div class="code_line">&nbsp;&nbsp; &nbsp;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;DWORD dwInt = 0;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;// !!! Важно выделить память под буфер через VirtualAlloc, чтобы она была выровнена для надежной работы с FILE_FLAG_NO_BUFFERING</div><div class="code_line">&nbsp;&nbsp; &nbsp;byte* buffer = (byte*) VirtualAlloc(0, BUFSIZE, MEM_COMMIT, PAGE_READWRITE);</div><div class="code_line">&nbsp;&nbsp; &nbsp;// !!!</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;OVERLAPPED overloped;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.hEvent = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.Internal = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.InternalHigh = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.Offset = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.OffsetHigh = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;for (int i = 0; i &#60; 10000; i++)</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;dwInt = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while (1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;overloped.Offset = dwInt;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;memset(buffer, 0, BUFSIZ);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD res = ReadFileEx(m_hFile, buffer, BUFSIZ, &amp;overloped, &amp;__IOCompletionRoutine);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((res == FALSE) &amp;&amp; (GetLastError() == ERROR_HANDLE_EOF))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;break old -%d\n&quot;, i);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// !!! SleepEx ставим тут, чтобы точно дождаться завершения текущей операции</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SleepEx(INFINITE, TRUE);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD nBytesRead = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((GetOverlappedResult(m_hFile, &amp;overloped, &amp;nBytesRead, FALSE) == FALSE) &amp;&amp; (GetLastError() == ERROR_HANDLE_EOF))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (overloped.Offset == 0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;big ass %d\n&quot;, i);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.Offset -%d\n&quot;, overloped.Offset);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.OffsetHigh -%d\n&quot;, overloped.OffsetHigh);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.Internal -%d\n&quot;, overloped.Internal);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.InternalHigh -%d\n&quot;, overloped.InternalHigh);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.hEvent -%d\n&quot;, overloped.hEvent);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.Pointer -%d\n&quot;, overloped.Pointer);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Sleep(100000);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dwInt += BUFSIZ;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;S_OK&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;Sleep(60000);</div><div class="code_line">&nbsp;&nbsp; &nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script>]]></description>
        <author>Pacific</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688379</guid>
        <pubDate>Wed, 12 Oct 2016 09:53:00 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688379</link>
        <description><![CDATA[nik531: <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#include &quot;stdafx.h&quot;</div><div class="code_line">#include &#60;windows.h&#62;</div><div class="code_line">#include &#60;stdio.h&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">#define BUFSIZE 4096</div><div class="code_line">&nbsp;</div><div class="code_line">HANDLE hEvent = CreateEvent(NULL,FALSE,FALSE,NULL);</div><div class="code_line">&nbsp;</div><div class="code_line">VOID CALLBACK __IOCompletionRoutine( DWORD dwErrorCode, DWORD dwSize, LPOVERLAPPED lpOverlapped )</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;//printf(&quot;__IOCompletionRoutine(%d)\n&quot;, dwErrorCode);</div><div class="code_line">&nbsp;&nbsp; &nbsp;::SetEvent(hEvent);</div><div class="code_line">};</div><div class="code_line">&nbsp;</div><div class="code_line">int _tmain(int argc, _TCHAR* argv[])</div><div class="code_line">{</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;// Открываем файл</div><div class="code_line">&nbsp;&nbsp; &nbsp;HANDLE m_hFile = CreateFileW( </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;L&quot;C:\test.test&quot;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ | GENERIC_WRITE,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_SHARE_READ,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;NULL,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_ATTRIBUTE_NORMAL | </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_NO_BUFFERING | </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_OVERLAPPED | </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_WRITE_THROUGH | </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_RANDOM_ACCESS,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;NULL</div><div class="code_line">&nbsp;&nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;DWORD dwInt = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;byte buffer [BUFSIZE] = {0}; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;OVERLAPPED overloped;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.hEvent = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.Internal = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.InternalHigh = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.Offset = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;overloped.OffsetHigh = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;for(int i=0;i&#60;10000;i++)</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;dwInt = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while(1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;overloped.Offset = dwInt;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;memset(buffer,0, BUFSIZ);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD res = ReadFileEx(m_hFile, buffer, BUFSIZ, &amp;overloped, &amp;__IOCompletionRoutine);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD error = GetLastError();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if((res == FALSE) &amp;&amp; GetLastError() == ERROR_HANDLE_EOF)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;break old -%d\n&quot;, i);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD nBytesRead = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if((GetOverlappedResult(m_hFile, &amp;overloped, &amp;nBytesRead, FALSE) == FALSE) &amp;&amp; (GetLastError() == ERROR_HANDLE_EOF))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(overloped.Offset == 0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;big ass %d\n&quot;,i);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.Offset -%d\n&quot;, overloped.Offset);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.OffsetHigh -%d\n&quot;, overloped.OffsetHigh);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.Internal -%d\n&quot;, overloped.Internal);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.InternalHigh -%d\n&quot;, overloped.InternalHigh);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.hEvent -%d\n&quot;, overloped.hEvent);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;overloped.Pointer -%d\n&quot;, overloped.Pointer);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Sleep(100000);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;break new -%d\n&quot;, i);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;::WaitForSingleObjectEx( hEvent, INFINITE, TRUE );</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dwInt += BUFSIZ;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;::WaitForSingleObjectEx( hEvent, INFINITE, TRUE );</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;S_OK&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;Sleep(60000);</div><div class="code_line">&nbsp;&nbsp; &nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div><br>
вот на этом примере падает, редко когда до тысячи операция чтения проходит<br>
[attach=#0][/attach] <br>
не могу добавить файл но 4 кило байта нулей.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688366</guid>
        <pubDate>Wed, 12 Oct 2016 09:05:50 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688366</link>
        <description><![CDATA[Pacific: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688360'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-12T08:38:51+00:00">12.10.16, 08:38</time></span><div class='quote '>К сожалению на тестовом примере повторить поведение не получается. Возможно я что делаю не так как в большом проекте реализовано. А большой проект слишком большой. Состоит больше чем из десятка Dll и десятка lib. Есть конечно большая вероятность что там делается что то не правильно. </div></div><br>
Самая частая ошибка - когда одна и та же структура OVERLAPPED используется одновременно для нескольких разных (одновременных) операций I/O. Например, вызов в цикле ReadFileEx с одной и той же lpOverlapped, не дожидаясь окончания предыдущей операции. В этом случае можно словить самые разные глюки.]]></description>
        <author>Pacific</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688360</guid>
        <pubDate>Wed, 12 Oct 2016 08:38:51 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688360</link>
        <description><![CDATA[nik531: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688349'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Cfon &#064; <time class="tag-quote__quoted-time" datetime="2016-10-12T07:50:32+00:00">12.10.16, 07:50</time></span><div class='quote '><div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688344'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-12T07:10:04+00:00">12.10.16, 07:10</time></span><div class='quote '>разработчик делал всё по документации. Будет любезны поддерживать то что за документировали.</div></div><br>
какой такой документации? документации для какой винды? 10ки? 8?<br>
и вы будте любезны юзать ее там для какой платформы они ее разработали  :whistle: <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2016-10-12T07:51:45+00:00">12.10.16, 07:51</time></span></span><br>
ты вообще читал ее описание? вот почитай <br>
<a class='tag-url' href='https://msdn.microsoft.com/ru-ru/library/windows/desktop/aa365468(v=vs.85).aspx' target='_blank'><em class='tag-i'>https://msdn.microsoft.com/ru-ru/library/windows/desktop/aa365468(v=vs.85).aspx</em></a></div></div><br>
как раз от туда и цитируем MSDN<br>
а вот что было обещанно разработчику на момент написания. <br>
[attach=#0][/attach]<br>
и тут возникает вопрос. судя по ссылке приведённой вами так эта функция работает на winXP. А судя по скриншоту XP работает не так. либо MS лгали в 2008 году либо лгут сейчас. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2016-10-12T08:57:40+00:00">12.10.16, 08:57</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688350'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Pacific &#064; <time class="tag-quote__quoted-time" datetime="2016-10-12T07:52:14+00:00">12.10.16, 07:52</time></span><div class='quote '><strong class='tag-b'>nik531</strong><br>
Я просил весь код, а не одну функцию. Как она вызывается, как инициализируется lpOverlapped перед вызовом. Весь код, который можно скомпилировать и запустить. У меня как раз Win10, могу проверить.</div></div><br>
К сожалению на тестовом примере повторить поведение не получается. Возможно я что делаю не так как в большом проекте реализовано. А большой проект слишком большой. Состоит больше чем из десятка Dll и десятка lib. Есть конечно большая вероятность что там делается что то не правильно. <br>
Но MSDN чётко говорит. If ReadFileEx attempts to read past the end-of-file (EOF), the call to GetOverlappedResult for that operation returns FALSE and GetLastError returns ERROR_HANDLE_EOF.<br>
Что я понимаю как если вы вызвали ReadFileEx для участка файла лежащего за его пределами. GetOverlappedResult должен венуть FALSE и GetLastError returns ERROR_HANDLE_EOF.<br>
но если поставить точку останова при выполнении этого условия то не стабильно но встречается ситуация когда ReadFileEx вызвано для нулевого смещения и чтать ещё есть чего а результат GetLastError после вызова GetOverlappedResult равен ERROR_HANDLE_EOF;<br>
Попробую разобраться в чём дело.  <br>
а открывается файл и инциализруется оверлопед струкура такаже как и в тестовом примере в первом посте. чтобы не загружать пост не буду повторять.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688350</guid>
        <pubDate>Wed, 12 Oct 2016 07:52:14 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688350</link>
        <description><![CDATA[Pacific: <strong class='tag-b'>nik531</strong><br>
Я просил весь код, а не одну функцию. Как она вызывается, как инициализируется lpOverlapped перед вызовом. Весь код, который можно скомпилировать и запустить. У меня как раз Win10, могу проверить.]]></description>
        <author>Pacific</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688349</guid>
        <pubDate>Wed, 12 Oct 2016 07:50:32 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688349</link>
        <description><![CDATA[Cfon: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688344'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-12T07:10:04+00:00">12.10.16, 07:10</time></span><div class='quote '>разработчик делал всё по документации. Будет любезны поддерживать то что за документировали.</div></div><br>
какой такой документации? документации для какой винды? 10ки? 8?<br>
и вы будте любезны юзать ее там для какой платформы они ее разработали  :whistle: <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2016-10-12T07:51:45+00:00">12.10.16, 07:51</time></span></span><br>
ты вообще читал ее описание? вот почитай <br>
<a class='tag-url' href='https://msdn.microsoft.com/ru-ru/library/windows/desktop/aa365468(v=vs.85).aspx' target='_blank'><em class='tag-i'>https://msdn.microsoft.com/ru-ru/library/windows/desktop/aa365468(v=vs.85).aspx</em></a>]]></description>
        <author>Cfon</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688344</guid>
        <pubDate>Wed, 12 Oct 2016 07:10:04 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688344</link>
        <description><![CDATA[nik531: <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">HRESULTRead( LPVOID pBuffer, LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE pIOCompletionRoutine )</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;// Вызываем соответствующую функцию WinAPI</div><div class="code_line">&nbsp;&nbsp; &nbsp;BOOL bResult = ReadFileEx(</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;m_hFile,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;pBuffer,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;m_dwPageSize,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;lpOverlapped,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;pIOCompletionRoutine</div><div class="code_line">&nbsp;&nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;// Возвращаем результат</div><div class="code_line">&nbsp;&nbsp; &nbsp;if(bResult == TRUE)</div><div class="code_line">&nbsp;&nbsp; &nbsp;{//не спешим радоваться Win 10 вернёт TRUE даже если мы читаем за пределами файла проверим </div><div class="code_line">&nbsp;&nbsp; &nbsp; //В MSDN написано </div><div class="code_line">&nbsp;&nbsp; &nbsp; //If ReadFileEx attempts to read past the end-of-file (EOF), the call to GetOverlappedResult for that operation returns FALSE and GetLastError returns ERROR_HANDLE_EOF.</div><div class="code_line">&nbsp;&nbsp; &nbsp; //будем надеятся что это правда </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;DWORD nBytesRead = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if((GetOverlappedResult(m_hFile, lpOverlapped, &amp;nBytesRead, FALSE) == FALSE)&amp;&amp;(GetLastError( ) == &nbsp;ERROR_HANDLE_EOF))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;return( ( bResult ) ? S_OK : HRESULT_FROM_WIN32( GetLastError( ) ) );</div><div class="code_line">}</div></ol></div></div></div></div><br>
и вот return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); происходит при начале чтения файла. lpOverlapped смешение равно ноль. файл большего размера чем буфер.<br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '><br>
нет мля они тебя забыли спросить <br>
</div></div><br>
разработчик делал всё по документации. Будет любезны поддерживать то что за документировали.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688341</guid>
        <pubDate>Wed, 12 Oct 2016 06:58:08 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688341</link>
        <description><![CDATA[Pacific: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688329'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-12T05:55:13+00:00">12.10.16, 05:55</time></span><div class='quote '>GetOverlappedResult иногда возвращает ERROR_HANDLE_EOF хотя файл читается с начала и до конца ещё далеко. </div></div><br>
Неправильно используешь overlapped I/O. Весь код покажи, в котором у тебя такая ошибка.]]></description>
        <author>Pacific</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688330</guid>
        <pubDate>Wed, 12 Oct 2016 06:11:11 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688330</link>
        <description><![CDATA[Cfon: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688329'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-12T05:55:13+00:00">12.10.16, 05:55</time></span><div class='quote '>то есть эти люди с майкрософта поменяли поведение базовой функции. так мало того что поменяли так они сделали это ещё с ошибкой, GetOverlappedResult иногда возвращает ERROR_HANDLE_EOF хотя файл читается с начала и до конца ещё далеко.</div></div><br>
нет мля они тебя забыли спросить  :D <br>
и как така ошибка? то что ты не правильно юзаешь ее и не умеешь читать на буржуйском не значит что там ошибка  :whistle:]]></description>
        <author>Cfon</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688329</guid>
        <pubDate>Wed, 12 Oct 2016 05:55:13 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688329</link>
        <description><![CDATA[nik531: посмотрел я MSDN для VS 2008 там на чистом буржуйском написанно <br>If ReadFileEx attempts to read past the end of the file, the function returns zero, and GetLastError returns ERROR_HANDLE_EOF.<br>в MSDN для текущей версии это звучит так <br>If ReadFileEx attempts to read past the end-of-file (EOF), the call to GetOverlappedResult for that operation returns FALSE and GetLastError returns ERROR_HANDLE_EOF.<br>то есть эти люди с майкрософта поменяли поведение базовой функции. так мало того что поменяли так они сделали это ещё с ошибкой, GetOverlappedResult иногда возвращает ERROR_HANDLE_EOF хотя файл читается с начала и до конца ещё далеко. <br>пока проверка в двух местах спасает :) посмотрим далее.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688326</guid>
        <pubDate>Wed, 12 Oct 2016 03:12:59 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688326</link>
        <description><![CDATA[nik531: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688279'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-11T09:58:11+00:00">11.10.16, 09:58</time></span><div class='quote '>If ReadFileEx attempts to read past the end-of-file (EOF), the call to GetOverlappedResult for that operation returns FALSE and GetLastError returns ERROR_HANDLE_EOF.</div></div><br>
а как тогда понимать вот эту строчку с мсдн ?]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688304</guid>
        <pubDate>Tue, 11 Oct 2016 14:43:25 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688304</link>
        <description><![CDATA[Pacific: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3688279'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-11T09:58:11+00:00">11.10.16, 09:58</time></span><div class='quote '>пока склоняюсь к тому чтобы проверять код ошибки в двух местах при вызове и ReadFileEx и внутри __IOCompletionRoutine</div></div><br>
Это и есть единственный правильный вариант.]]></description>
        <author>Pacific</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688279</guid>
        <pubDate>Tue, 11 Oct 2016 09:58:11 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3688279</link>
        <description><![CDATA[nik531: не всё оказалась так просто. GetOverlappedResul иногда возвращает явно 38 код ошибки хотя конца файла ещё не достиг. Пока не понял почему так происходит. <br>Обрабатывать код ошибка в __IOCompletionRoutine тоже как-то не понятно. в Win7 для последнего блока она не вызывается. Вопщем пока склоняюсь к тому чтобы проверять код ошибки в двух местах при вызове и ReadFileEx и внутри __IOCompletionRoutine и отказаться от GetOverlappedResult.<br>хотя в MSDN написано<br>If ReadFileEx attempts to read past the end-of-file (EOF), the call to GetOverlappedResult for that operation returns FALSE and GetLastError returns ERROR_HANDLE_EOF.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687497</guid>
        <pubDate>Tue, 04 Oct 2016 08:56:49 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687497</link>
        <description><![CDATA[Cfon: старик зачем тут sleep? что за костыли? :wacko:]]></description>
        <author>Cfon</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687482</guid>
        <pubDate>Tue, 04 Oct 2016 07:35:15 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687482</link>
        <description><![CDATA[Pacific: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3687456'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-04T04:58:59+00:00">04.10.16, 04:58</time></span><div class='quote '>но почему в разных ОС поведении разное. и даже Sleep себя по разному ведёт. и до появления win 10 всё стабильно работало 10 лет </div></div><br>
А не надо надеяться на недокументированное поведение, которое может поменяться не только при смене ОС, но даже после обычного патча или установки антивируса например. Раньше у тебя она сразу возвращала 0 (то есть ошибку, как написано в MSDN для этой функции), и код ошибки 38 - конец файла. А теперь возвращает 1, то есть была успешно запущена асинхронная операция: &quot;If the function succeeds, the calling thread has an asynchronous I/O operation pending: the overlapped read operation from the file. When this I/O operation completes, and the calling thread is blocked in an alertable wait state, the system calls the function pointed to by lpCompletionRoutine, and the wait state completes with a return code of WAIT_IO_COMPLETION.&quot;, и код ошибки 38 ты уже получишь в IOCompletionRoutine. Что она вернет в каждом конкретном случае - <strong class='tag-b'>не документировано</strong>, но все варианты в MSDN описаны, и их надо обрабатывать.]]></description>
        <author>Pacific</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687467</guid>
        <pubDate>Tue, 04 Oct 2016 06:55:01 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687467</link>
        <description><![CDATA[Cfon: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=409663&view=findpost&p=3687456'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>nik531 &#064; <time class="tag-quote__quoted-time" datetime="2016-10-04T04:58:59+00:00">04.10.16, 04:58</time></span><div class='quote '>и даже вот тут написанно <a class='tag-url' href='http://www.vsokovikov.narod.ru/New_MSDN_API/Menage_files/fn_readfileex.htm' target='_blank'>http://www.vsokovikov.narod.ru/New_MSDN_AP..._readfileex.htm</a> что должно возвращать 0:( вопщем в майкросфоте негодяии. Пришли и передлали всё по совему. А программка 10 лет стабильно работала :(</div></div><br>
она и в 10ке возвращает 0  :whistle:]]></description>
        <author>Cfon</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687456</guid>
        <pubDate>Tue, 04 Oct 2016 04:58:59 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687456</link>
        <description><![CDATA[nik531: но почему в разных ОС поведении разное. и даже Sleep себя по разному ведёт. и до появления win 10 всё стабильно работало 10 лет :( <br>
и даже вот тут написанно <a class='tag-url' href='http://www.vsokovikov.narod.ru/New_MSDN_API/Menage_files/fn_readfileex.htm' target='_blank'>http://www.vsokovikov.narod.ru/New_MSDN_AP..._readfileex.htm</a> что должно возвращать 0:( вопщем в майкросфоте негодяии. Пришли и передлали всё по совему. А программка 10 лет стабильно работала :( <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2016-10-04T05:30:11+00:00">04.10.16, 05:30</time></span></span><br>
если добавить в конце проверку GetOverlappedResult то тогда конец файла находится и это хорошо <br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&nbsp;&nbsp; &nbsp;DWORD nBytesRead = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;GetOverlappedResult(m_hFile, &amp;temp, &amp;nBytesRead, FALSE);</div><div class="code_line">&nbsp;&nbsp; &nbsp;error = GetLastError();</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;error over- %d\n&quot;, error);</div></ol></div></div></div></div>]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687339</guid>
        <pubDate>Mon, 03 Oct 2016 13:26:54 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687339</link>
        <description><![CDATA[Pacific: <strong class='tag-b'>nik531</strong><br>
У тебя же OVERLAPPED I/O, надо все коды ошибок смотреть внутри IOCOmpletionRoutine, а не сразу после вызова ReadFileEx. Он вернул 0 - значит, ошибки по <strong class='tag-b'>запуску операции чтения</strong> не было, а вот ее результат ты узнаешь уже в IOCOmpletionRoutine.]]></description>
        <author>Pacific</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687316</guid>
        <pubDate>Mon, 03 Oct 2016 11:16:07 +0000</pubDate>
        <title>Win 10 и ReadFileEx</title>
        <link>https://forum.sources.ru/index.php?showtopic=409663&amp;view=findpost&amp;p=3687316</link>
        <description><![CDATA[nik531: Странное поведение ReadFileEx в Win 10<br>
не находит конец файла<br>
ниже приведён код тестового приложения<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">// temp.cpp : Defines the entry point for the console application.</div><div class="code_line">//</div><div class="code_line">&nbsp;</div><div class="code_line">#include &quot;stdafx.h&quot;</div><div class="code_line">#include &#60;windows.h&#62;</div><div class="code_line">#include &#60;stdio.h&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">#define BUFSIZE 4096</div><div class="code_line">&nbsp;</div><div class="code_line">VOID CALLBACK __IOCompletionRoutine( DWORD dwErrorCode, DWORD dwSize, LPOVERLAPPED lpOverlapped )</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;__IOCompletionRoutine\n&quot;);</div><div class="code_line">};</div><div class="code_line">&nbsp;&nbsp; &nbsp;int _tmain(int argc, _TCHAR* argv[])</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;OVERLAPPED temp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;temp.hEvent = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;temp.Internal = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;temp.InternalHigh = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;temp.Offset = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;temp.OffsetHigh = 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;byte buffer [BUFSIZE] = {0};</div><div class="code_line">&nbsp;&nbsp; &nbsp;// Открываем файл</div><div class="code_line">&nbsp;&nbsp; &nbsp;HANDLE m_hFile = CreateFileW( </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;L&quot;C:\test.test&quot;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ | GENERIC_WRITE,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_SHARE_READ,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;NULL,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FILE_ATTRIBUTE_NORMAL | </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_NO_BUFFERING | </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_OVERLAPPED | </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_WRITE_THROUGH | </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_FLAG_RANDOM_ACCESS,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;NULL</div><div class="code_line">&nbsp;&nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;DWORD res = ReadFileEx(m_hFile, buffer, BUFSIZ, &amp;temp, &amp;__IOCompletionRoutine);</div><div class="code_line">&nbsp;&nbsp; &nbsp;SleepEx(5000, TRUE);</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;ReadFileEx- %d\n&quot;, res);</div><div class="code_line">&nbsp;&nbsp; &nbsp;DWORD error = GetLastError();</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;error- %d\n&quot;, error);</div><div class="code_line">&nbsp;&nbsp; &nbsp;/*for(int i=0; i&#60; BUFSIZ; i++)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;%d &quot;, buffer[i]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;\n&quot;);*/</div><div class="code_line">&nbsp;&nbsp; &nbsp;temp.Offset = BUFSIZE;</div><div class="code_line">&nbsp;&nbsp; &nbsp;memset(buffer,0, BUFSIZ);</div><div class="code_line">&nbsp;&nbsp; &nbsp;res = ReadFileEx(m_hFile, buffer, BUFSIZ, &amp;temp, &amp;__IOCompletionRoutine);</div><div class="code_line">&nbsp;&nbsp; &nbsp;SleepEx(5000, TRUE);</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;ReadFileEx- %d\n&quot;, res);</div><div class="code_line">&nbsp;&nbsp; &nbsp;error = GetLastError();</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;error- %d\n&quot;, error);</div><div class="code_line">&nbsp;&nbsp; &nbsp;/*for(int i=0; i&#60; BUFSIZ; i++)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;%d &quot;, buffer[i]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;\n&quot;);*/</div><div class="code_line">&nbsp;&nbsp; &nbsp;Sleep(60000);</div><div class="code_line">&nbsp;&nbsp; &nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div><br>
файл test.test ровно 4 килобайта[attach=#0][/attach]. <br>
на ОС до Win 10 При второй попытки чтения возвращается код ошибки 0 и LastError (38)<br>
а под Win 10 Всегда возвращается 1 и 0 соответственно. получаем без конечный файл на чтение. что не есть хорошо<br>
может кто сталкивался с такой проблемой?<br>
и под Win10 оно не ждёт 5 секунда а сразу выводит резултаты.]]></description>
        <author>nik531</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      </channel>
      </rss>
	