Jump to content
faustf

memory mapped duplicated value

Recommended Posts

Posted (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 by faustf

Share this post


Link to post
Share on other sites

Hello. Consider to post a whole example all the time, to be able for us to reproduce the whole issue.

 

 

Saludos

Share this post


Link to post
Share on other sites
Posted (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 by faustf

Share this post


Link to post
Share on other sites
13 minutes ago, faustf said:

i dont  want  erase

And how exactly will you be synchronizing the sender and receiver ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Posted (edited)

what is mailsot ??

but i think yes   the  program work in mem  without real file

Edited by faustf

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 )

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...