No announcement yet.

DLL question

  • Filter
  • Time
  • Show
Clear All
new posts

  • DLL question

    Dear Forum,

    Is it possible to "share" loaded DLL for over one calling task?
    I want to communicate via RS232 with external equipment with ability
    to read received data by few tasks. I know I can do it by disk file,
    but how to do that, reading only memory variables?

    Thanks in advance



  • #2
    Making a filemapping object (search here)
    Or an easy way to create a filemapping object is using WM_SETTEXT.

    Create a window and retrieve the text sent from another app.
    The data is maintained by Windows in this part. case.
    Even between a 16 and 32 bit app.

    I don't think it's usefull for high speed (don't know)

    [email protected]


    • #3
      ' Example of memory mapped files. MapSizeInBytes is the size of the shared memory
      ' If you start a number of instances of the program, you,ll see that all read the same value.
      #Compile Exe
      #Include ""
      Global lCnt     As Long
      Global hTimer   As Long
      Global hMap     As Long
      Global hMapView As Long
      Global hDlg     As Long
      Global lPtr     As Long Ptr
      %ID_BTN = 4000
      %ID_TMR = 4001
      CallBack Function MainCb ()
        Select Case CbMsg
          Case %WM_INITDIALOG
            hTimer = SetTimer (CbHndl, %ID_TMR, 100, 0)
          Case %WM_COMMAND
            Incr @lPtr
            Control Set Text hDlg,%ID_BTN,Trim$(Str$(@lPtr))
          Case %WM_TIMER
            If lCnt <> @lPtr Then
              lCnt = @lPtr
              Control Set Text hDlg,%ID_BTN,Trim$(Str$(@lPtr))
            End If
          Case %WM_DESTROY
            KillTimer hTimer, %ID_TMR
            UnMapViewOfFile ByVal hMapView
            CloseHandle hMap
        End Select
      End Function
      Function PbMain () As Long
        Local MapName As Asciiz * %MAX_PATH, MapSizeInBytes As Long, lRet As Long
        MapName           = "Mymap"
        MapSizeInBytes    = 65535
        hMap = CreateFileMapping (ByVal -1, ByVal %Null, ByVal %PAGE_READWRITE, _
               ByVal 0, MapSizeInBytes, MapName)
        lRet = GetLastError
        If (hMap) Or ((hMap = 0) And (lRet = %ERROR_ALREADY_EXISTS)) Then
          hMapView = MapViewOfFile (hMap, ByVal %FILE_MAP_ALL_ACCESS, 0, 0, 0)
          If hMapView Then
            lPtr = hMapView
            Dialog New 0, "Test of memory mapped file",,,50,50, %WS_SYSMENU, To hDlg
            Control Add Button, hDlg, %ID_BTN,"Press me",10,10,50,15
            Dialog Show Modal hDlg Call MainCb
            MsgBox "Unable to map view of file",%MB_ICONSTOP,"Error!"
          End If
          MsgBox "Unable to create file mapping",%MB_ICONSTOP,"Error!"
        End If
      End Function
      mailto[email protected][email protected]</A>

      [This message has been edited by Peter Lameijn (edited November 22, 2000).]

      "Simplicity is a prerequisite for reliability"