Jump to content

Recommended Posts

The shared memory content can be read by using a similar code like the following Delphi procedure:

Const
 sharedmem_name = 'EVEREST_SensorValues';

Function  ExtApp_SharedMem_ReadBuffer(bu:PChar;bu_size:DWord):Boolean;

Var
 mappedData : PChar;
 th : THandle;

Begin
 Result:=False;

 th:=CreateFileMapping(INVALID_HANDLE_VALUE,0,PAGE_READONLY,0,bu_size,sharedmem_name);

 If th<>INVALID_HANDLE_VALUE Then
 Begin
   mappedData:=MapViewOfFile(sharedmem_handle,FILE_MAP_READ,0,0,0);
   If mappedData<>Nil Then
   Begin
     StrLCopy(bu,mappedData,bu_size);
     If UnmapViewOfFile(mappedData) Then Result:=True;
   End;
   CloseHandle(th);
 End;
End;

Is it possible to do something like that? If so could someone help me with a start?


[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post


Link to post
Share on other sites

I know this is a very old thread, but annoyingly it keeps popping up if you search for things like Autoit, AIDA64 ,and shared memory. So I decided to fix it...

I've retained the same overall structure of the example Delphi code currently found in the AIDA64 documentation, and also kept the same variable names. There's only a few minor things done differently due to how AutoIt handles pointers. But, this function is not very useful in its current state: AIDA64 does not provide a buffer size value. Basically if $bu_size goes beyond the shared memory mapping, you get an exception and nothing works. This means a bit of trial and error might be required until you get all the data you want. Ref: https://forums.aida64.com/topic/4639-shared-memory-access-denied/

One workaround is to use _WinAPI_GetSystemInfo() <WinAPISys.au3> to get dwPageSize ($aArray[1]). The value of dwPageSize is usually 4096. Use this as an offset for $mappedData, and continue reading $bu until you get to the end. Also, if you use type BYTE[] instead of type CHAR[] you get the binary (hex) values, and can stop reading when you read 00 at the end of $bu.  See this post here with a working example that demonstrates this: 

 

Delphi example code translated to AutoIt3 as OP requested:

#NoTrayIcon
#include <WinAPIFiles.au3>
#include <WinAPISys.au3>

; #INDEX# ===========================================================================================================================
; Title .........: AIDA64 Shared Memory Example for AutoIt3
; Author(s) .....: demux4555
; Description ...: AutoIt3 version of the Delphi example found in the AID64 documentation.
; Reference .....: https://www.aida64.co.uk/user-manual/external-applications
; ===================================================================================================================================

Global $sharedmem_name = 'AIDA64_SensorValues'

Global $sharedmem_data
Global $return = ExtApp_SharedMem_ReadBuffer($sharedmem_data, 1024)

_Echo()
_Echo("> return   = " & $return)                                    ; The return value. Will be True of everything went ok.
_Echo("> length   = " & StringLen($sharedmem_data))                 ; The number of characters read from shared memory.
_Echo("> data     = " & $sharedmem_data)                            ; The actual data.
_Echo("> data(40) = " & "..." & StringRight($sharedmem_data, 40))   ; shows the 40 right-most characters, allowing you to explore the data by changing value of $bu_size until you reach the end.
_Echo()

Exit

Func ExtApp_SharedMem_ReadBuffer(ByRef $bu, $bu_size)
    Local $th = _WinAPI_OpenFileMapping($sharedmem_name, $FILE_MAP_READ)
    Local $Result = False
    If IsPtr($th) Then
        Local $mappedData = _WinAPI_MapViewOfFile($th, 0, 0, $FILE_MAP_READ)
        If IsPtr($mappedData) Then
            Local $tData = DllStructCreate("CHAR[" & $bu_size & "]", $mappedData)
            $bu = DllStructGetData($tData, 1)
            If _WinAPI_UnmapViewOfFile($mappedData) Then $Result = True
        EndIf
        _WinAPI_CloseHandle($th)
    EndIf
    Return $Result
EndFunc

Func _Echo($_data = "")
    ConsoleWrite($_data & @CRLF)
EndFunc

 

Edited by Irios

863nP4W.png discord.me/autoit  (unofficial)

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...