1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to? Accessing alias shared memory

Discussion in 'Suggestions' started by Gisle Vanem, Jun 8, 2017.

  1. Gisle Vanem

    Joined:
    Dec 30, 2015
    Messages:
    2
    Likes Received:
    0
    Don't laugh, but I still use 4NT (v5.00, Build 128, Unicode) under Windows 10. It still work fine for my needs.
    I'd like to access the alias-list that 4NT keeps in a shared-memory region. From ProcessExplorer, I see sections like:
    \Sessions\1\BaseNamedObjects\Sharemem4NTUAliasGisle

    How can I access such section from another instance of 4NT (or cmd, or whatever)?
    And what is the format these, pure text?
     
  2. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    698
    Likes Received:
    8
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,071
    Likes Received:
    30
    To elaborate on what Joe said ...
    Two 4NTs running simultaneously shouls both be able to access them as long as the "Global" options are set in both instances. The purpose of SHRALIAS is to keep the memory-mapped files open even when no 4NTs are running; so any 4NT will use the lists that were previously in use. Any other access is something you'll have to program yourself (more on that below).
    In recent versions of the product (now called TCC) the memory-mapped files are Unicode. That's OK with 4NTv8 which is as far back as I can go. Since your files have "U" in their names, I suppose yours are Unicode. Accessing the lists programmatically involves the following
    Code:
    (1) MapFileHandle = OpenFileMapping (with names like the one you mentioned, Sharemem4NTUAlias<username>).  In newer versions that's just SharememUAlias<user_name>.
    (2) MapFilePointer = (WCHAR*) MapViewOfFile(MapFileHandle, ...
    At this point, MapFilePointer points to the first character if the memory-mapped file.
    When you're done,
    Code:
    UnmapViewOfFile(MapFilePointer)
    CloseHandle(MapFileHandle)
    
     
  4. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    698
    Likes Received:
    8
    Here's code that will display the first 1000 bytes of your Alias MMF;
    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.inc"
    
    FUNCTION PBMAIN () AS LONG
      LOCAL hMap AS LONG, MapName AS ASCIIZ * 64, lRet AS LONG, lString AS STRING
     
      MapName = "SharememUAliasjlc" '<-- Change this to your MapName
     
      lRet = OpenFileMapping _
             (%FILE_MAP_ALL_ACCESS,_ ' access mode
             BYVAL %NULL, _ ' inherit flag
             MapName) ' pointer to name of file-mapping object
    
      IF lRet THEN
        hMap = MapViewOfFile _
               (lRet,_ ' file-mapping object to map into address space
               %FILE_MAP_ALL_ACCESS,_ ' access mode
               0,_ ' high-order 32 bits of file offset
               0,_ ' low-order 32 bits of file offset
               0) ' number of bytes to map
    
        PRINT ACODE$(PEEK$(hMap,1000))
      ELSE
        STDOUT "Cannot open file mapping" + CHR$(13) + "Filemap must exist!"
      END IF
      UnmapViewOfFile BYVAL lRet
      CloseHandle hMap
    END FUNCTION
    
    Joe
     
  5. Gisle Vanem

    Joined:
    Dec 30, 2015
    Messages:
    2
    Likes Received:
    0
    Thanks a lot both Joe and Vince. I will try this code and information later.
     

Share This Page