faustf Posted July 17, 2020 Share Posted July 17, 2020 (edited) hi guys i continued to try to understand a memory mapped file , it work but when i read a memory mapped file (the source put a stream data) in autoit repeat a data example i have in memory mapped this string VOLUME -- 6 after 1 second have VOLUME -- 5 , but autoit return me first time VOLUME -- 6 and second time VOLUME -- 652 why ? with c# work regular #NoTrayIcon #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <WinAPIHObj.au3> #include <WinAPIError.au3> Opt('WinWaitDelay', 0) while 1 _Receiver() WEnd Func _Receiver() Local $hMapping = _WinAPI_OpenFileMapping('Test') If $hMapping = 0 Then MsgBox(0, '', _WinAPI_GetLastErrorMessage()) EndIf If Not $hMapping Then Return Local $pAddress = _WinAPI_MapViewOfFile($hMapping) ;ConsoleWrite("Demade " & $pAddress & @CRLF) Local $tData = DllStructCreate('byte[1000]', $pAddress) ;Sleep(2000) Local $bText = DllStructGetData($tData, 1) ;Get Text in Binary Local $tStr = DllStructCreate("char Str[100]", $pAddress + 56) ;Address+Offset where you write from C# //accessor.WriteArray(54 + 2, Buffer, 0, Buffer.Length); ;If $bText Then MsgBox(BitOR($MB_ICONINFORMATION, $MB_SYSTEMMODAL), "Show Binary (receiver)", $bText) If $tStr.Str Then ConsoleWrite ( $tStr.Str & @CRLF) _WinAPI_UnmapViewOfFile($pAddress) _WinAPI_CloseHandle($hMapping) EndFunc ;==>_Receiver Edited July 17, 2020 by faustf Link to comment Share on other sites More sharing options...
Danyfirex Posted July 18, 2020 Share Posted July 18, 2020 Hello. Consider to post a whole example all the time, to be able for us to reproduce the whole issue. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Nine Posted July 18, 2020 Share Posted July 18, 2020 Look at point 2 ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
faustf Posted July 18, 2020 Author Share Posted July 18, 2020 (edited) you intend ? On 6/28/2020 at 3:23 PM, Nine said: Couple of small issues I foresee: 1- Sender needs to close handle when file map is not required anymore 2- Receiver should erase content of the file map after reading so sender knows that content has been well received if yes i dont want erase , because is very fast the streaming of data , and i suppose when i erase could happen , i will erase a good data in c# work correct using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO.MemoryMappedFiles; class Program2 { static void Main() { MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen("Test", 1000); MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor(); ushort Size = accessor.ReadUInt16(54); byte[] Buffer = new byte[Size]; accessor.ReadArray(54 + 2, Buffer, 0, Buffer.Length); Console.WriteLine(ASCIIEncoding.ASCII.GetString(Buffer)); accessor.Dispose(); mmf.Dispose(); } } Edited July 18, 2020 by faustf Link to comment Share on other sites More sharing options...
Nine Posted July 18, 2020 Share Posted July 18, 2020 13 minutes ago, faustf said: i dont want erase And how exactly will you be synchronizing the sender and receiver ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
faustf Posted July 18, 2020 Author Share Posted July 18, 2020 but how C# synchronize ? Link to comment Share on other sites More sharing options...
Nine Posted July 18, 2020 Share Posted July 18, 2020 I am not a C# programmer. But the idea is quite straightforward. Sender should accumulate all the info until buffer is empty, then sends it all at once. Receiver retrieves the info and then empties the buffer. Very simple synchronization protocol. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
faustf Posted July 18, 2020 Author Share Posted July 18, 2020 and how is possible empties buffer ? Link to comment Share on other sites More sharing options...
argumentum Posted July 18, 2020 Share Posted July 18, 2020 hmmm, so you'd like to have \\mailsot\ behavior but in memory ?. [yes][no] ?. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
faustf Posted July 18, 2020 Author Share Posted July 18, 2020 (edited) what is mailsot ?? but i think yes the program work in mem without real file Edited July 18, 2020 by faustf Link to comment Share on other sites More sharing options...
argumentum Posted July 18, 2020 Share Posted July 18, 2020 so, since real time is not the same for C# and AutoIt ( or anything really ), you'd like to queue the data and read it in order. That way you don't slow down the C# and grab from AutoIt as fast as AutoIt will be able to run ( all these are my assumptions as you have to given a use scenario ). What is the use scenario ?. Maybe there is a simpler solution to your need. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
faustf Posted July 18, 2020 Author Share Posted July 18, 2020 the scenario is : suppose exist a application A, in this application you can create some plugin in C# (also create memory mapped file), (i just do it ) , this app every X second or millisecond (depend of net traffic day ) write a data stream (in string format) in memorymapped file , i want read it with autoit , and show in app B (app B, is writing in Autoit ) argumentum 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now