faustf Posted June 27, 2020 Share Posted June 27, 2020 hi guys i have in c# a code for memory mapped file (without file ) using System; using System.IO; using System.IO.MemoryMappedFiles; using System.Threading; class Program { // Process B: static void Main(string[] args) { try { using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("Test")) { Mutex mutex = Mutex.OpenExisting("testmapmutex"); mutex.WaitOne(); using (MemoryMappedViewStream stream = mmf.CreateViewStream(1, 0)) { BinaryWriter writer = new BinaryWriter(stream); writer.Write("0"); } mutex.ReleaseMutex(); } } catch (FileNotFoundException) { Console.WriteLine("Memory-mapped file does not exist. Run Process A first."); } } } exist a mode for read by Autoit ?? or exist some documentation i find only this but is old and give me rror in dll thankz at all Link to comment Share on other sites More sharing options...
Nine Posted June 27, 2020 Share Posted June 27, 2020 Help file : _WinAPI_CreateFileMapping () “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 June 28, 2020 Author Share Posted June 28, 2020 o thankz i try to catch a memory mapped file C# , in autoit build this simple code using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO.MemoryMappedFiles; namespace csharpmapmem1 { class Program { static void Main() { byte[] Buffer = ASCIIEncoding.ASCII.GetBytes("35;2020.06.26 10.00.01;ASK;1,12445;1"); MemoryMappedFile mmf = MemoryMappedFile.CreateNew("Test", 1000); MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor(); accessor.Write(54, (ushort)Buffer.Length); accessor.WriteArray(54 + 2, Buffer, 0, Buffer.Length); Console.WriteLine("Memory mapped file created"); Console.ReadLine(); accessor.Dispose(); mmf.Dispose(); } } } for Autoit #NoTrayIcon #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <WinAPIHObj.au3> Opt('WinWaitDelay', 0) _Receiver() Func _Receiver() Local $hMapping = _WinAPI_OpenFileMapping('Test') If Not $hMapping Then Return Local $pAddress = _WinAPI_MapViewOfFile($hMapping) Local $tData = DllStructCreate('USHORT[1000]', $pAddress) Local $sText Sleep(2000) $sText = DllStructGetData($tData, 1) DllStructSetData($tData, 1, '') If $sText Then MsgBox(BitOR($MB_ICONINFORMATION, $MB_SYSTEMMODAL), " (receiver)", " " & @CRLF & $sText) _WinAPI_UnmapViewOfFile($pAddress) _WinAPI_CloseHandle($hMapping) EndFunc ;==>_Receiver i run the first C# code and after run a autoit code , but not appear nothing and not return error whats wrong ??? thankz at all Link to comment Share on other sites More sharing options...
Danyfirex Posted June 28, 2020 Share Posted June 28, 2020 Hello. Just Make sure to review your code deeply. #NoTrayIcon #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <WinAPIHObj.au3> Opt('WinWaitDelay', 0) _Receiver() Func _Receiver() Local $hMapping = _WinAPI_OpenFileMapping('Test') If Not $hMapping Then Return Local $pAddress = _WinAPI_MapViewOfFile($hMapping) 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 MsgBox(BitOR($MB_ICONINFORMATION, $MB_SYSTEMMODAL), "Show Text (receiver)", $tStr.Str) _WinAPI_UnmapViewOfFile($pAddress) _WinAPI_CloseHandle($hMapping) EndFunc ;==>_Receiver Saludos faustf 1 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 June 28, 2020 Share Posted June 28, 2020 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 faustf 1 “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 June 28, 2020 Author Share Posted June 28, 2020 2 hours ago, Danyfirex said: Local $tData = DllStructCreate('byte[1000]', $pAddress) why you use here byte ? and why you use ? 2 hours ago, Danyfirex said: "char Str[100] 43 minutes ago, 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 yes of course , but first i must understund how work memory mapp. the finel plan is program A in c# put out a tream of data continuosly , and my program in Autoit read them in realtime and do somthing but a step at time :) thankz at all Link to comment Share on other sites More sharing options...
Nine Posted June 28, 2020 Share Posted June 28, 2020 3 minutes ago, faustf said: why you use here byte ? and why you use ? Because if you do not use byte or char or wchar, you will get only the first element of the array structure and not all the content of the array. “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 June 29, 2020 Author Share Posted June 29, 2020 questions i try to understund i insert a mem file in this scritp in c# expandcollapse popup#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.DrawingTools; using System.IO; using System.IO.MemoryMappedFiles; #endregion //This namespace holds Indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators { public class Aziocane : Indicator { MemoryMappedFile file; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "Aziocane"; Calculate = Calculate.OnBarClose; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; } else if (State == State.Configure) { file = MemoryMappedFile.CreateOrOpen("Test", 1000, MemoryMappedFileAccess.ReadWrite); } else if (State == State.Terminated) { file.Dispose(); } } protected override void OnBarUpdate() { //Add your custom indicator logic here. byte[] data = Encoding.UTF8.GetBytes ("This is a test vvvvvvvvvvvvv"); using (MemoryMappedViewAccessor accessor = file.CreateViewAccessor()) { accessor.Write(0,data.Length); } } } } and try to catch with this script in autoit but return me all zero Show Binary (receiver) 0x1c000.... and not return text #NoTrayIcon #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <WinAPIHObj.au3> #include <WinAPIError.au3> Opt('WinWaitDelay', 0) _Receiver() 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 MsgBox(BitOR($MB_ICONINFORMATION, $MB_SYSTEMMODAL), "Show Text (receiver)", $tStr.Str) _WinAPI_UnmapViewOfFile($pAddress) _WinAPI_CloseHandle($hMapping) EndFunc ;==>_Receiver whats wrong ? Link to comment Share on other sites More sharing options...
KaFu Posted June 29, 2020 Share Posted June 29, 2020 Is there a loop in you c# code? Afaik the memory mapped files only lives as long as a process has an open handle on it. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
faustf Posted June 29, 2020 Author Share Posted June 29, 2020 protected override void OnBarUpdate() { when the bar is update do it byte[] data = Encoding.UTF8.GetBytes ("This is a test vvvvvvvvvvvvv"); using (MemoryMappedViewAccessor accessor = file.CreateViewAccessor()) { accessor.Write(0,data.Length); } when attach the indicator over the chart ( only one time ) else if (State == State.Configure) { file = MemoryMappedFile.CreateOrOpen("Test", 1000, MemoryMappedFileAccess.ReadWrite); } when remove the indicator over chart (only one time ) else if (State == State.Terminated) { file.Dispose(); } therfore i suppose when barupdate rewrite the file like a stream , i suppose , but problably not understund good Link to comment Share on other sites More sharing options...
KaFu Posted June 29, 2020 Share Posted June 29, 2020 (edited) $pAddress is a pointer in receiver (= file mapping successful)? Try StringToBinary($bText) instead of the new structure. > Edit: BinaryToString($bText) of course 🤐 Edited June 29, 2020 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
faustf Posted June 29, 2020 Author Share Posted June 29, 2020 8 minutes ago, KaFu said: Try StringToBinary($bText) instead of the new structure. but with this Local $bText = DllStructGetData($tData, 1) ;Get Text in Binary convert text in binary why i must convert again ?? or you intend somthing like this ? Local $bText = StringToBinary($tData) ;Get Text in Binary Link to comment Share on other sites More sharing options...
KaFu Posted June 29, 2020 Share Posted June 29, 2020 $sText = BinaryToString($bText) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
faustf Posted June 29, 2020 Author Share Posted June 29, 2020 i just tryed also in this mode but nothing Link to comment Share on other sites More sharing options...
faustf Posted June 29, 2020 Author Share Posted June 29, 2020 this is a only msgbox recive https://ibb.co/sFGKbZh Link to comment Share on other sites More sharing options...
faustf Posted June 29, 2020 Author Share Posted June 29, 2020 i tryed also in this mode but nothing expandcollapse popupnamespace NinjaTrader.NinjaScript.Indicators { public class Aziocane : Indicator { MemoryMappedFile file; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "Aziocane"; Calculate = Calculate.OnBarClose; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; } else if (State == State.Configure) { MemoryMappedFile file = MemoryMappedFile.CreateNew("Test", 1000); } else if (State == State.Terminated) { file.Dispose(); } } protected override void OnBarUpdate() { //Add your custom indicator logic here. byte[] data = Encoding.UTF8.GetBytes ("This is a test vvvvvvvvvvvvv"); MemoryMappedViewAccessor accessor = file.CreateViewAccessor(); accessor.Write(54, (ushort)data.Length); accessor.WriteArray(54 + 2, data, 0, data.Length); } } } Link to comment Share on other sites More sharing options...
faustf Posted June 29, 2020 Author Share Posted June 29, 2020 in this mode work (for the moment ) , thankz at all expandcollapse popupnamespace NinjaTrader.NinjaScript.Indicators { public class Aziocane : Indicator { MemoryMappedFile file; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "Aziocane"; Calculate = Calculate.OnBarClose; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; } else if (State == State.Configure) { file = MemoryMappedFile.CreateOrOpen("Test", 1000, MemoryMappedFileAccess.ReadWrite); } else if (State == State.Terminated) { file.Dispose(); } } protected override void OnBarUpdate() { //Add your custom indicator logic here. byte[] data = ASCIIEncoding.ASCII.GetBytes("35;2020.06.26 10.00.01;ASK;1,12445;1"); MemoryMappedViewAccessor accessor = file.CreateViewAccessor(); accessor.Write(54, (ushort)data.Length); accessor.WriteArray(54 + 2, data, 0, data.Length); } } } Link to comment Share on other sites More sharing options...
faustf Posted July 14, 2020 Author Share Posted July 14, 2020 hi guys if someone can help me , my script not work in windows 10 , but work in win 7 , so the script not return error but retun i think only offset , but not a ascii text 0_o my code #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 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