Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

super easy Interprocess Communication

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • super easy Interprocess Communication

    Thanks to Pierre Bellisle!

    just three functions:

    Code:
    'Clipboard IPC
    
    
    #Include "Win32API.inc"
    
    
    Function MyFormat() As Long
         Local MyClipboardName As Asciiz * 20 'make this the same length as the name below
         MyClipboardName = "MyOwnClipboardFormat"                  
         Function    = RegisterClipboardFormat(MyClipboardName)
    End Function
    
    Function WriteMyClipBoard (ByVal Txt As String) As Long
     Local lpMem As Asciiz Ptr
     Local hMem  As Dword
    
     hMem       = GlobalAlloc(%GHND, Len(Txt) + 1)
     lpMem      = GlobalLock(hMem)
     @lpMem     = Txt
     GlobalUnlock hMem
     OpenClipboard 0
     SetClipboardData MyFormat, hMem
     CloseClipboard
     Function = 1
    End Function
    
    Function ReadMyClipboard() As String
       Local CData As Asciiz * 256, ClipDataPtr As Asciiz Ptr
       OpenClipboard 0
       ClipDataPtr = GetClipboardData(MyFormat)
       Function = @ClipDataPtr
       CloseClipboard
    End Function
    
    Function PBMain()
      
     If ReadMyClipboard <> "" Then Print "I found this on my clipboard " & ReadMyClipboard
     
     waitkey$
     
     WriteMyClipBoard(" I'll just put this on my clipboard")
      
    End Function
Working...
X