Can Events be Inter-Process?

后端 未结 2 603
挽巷
挽巷 2021-02-06 09:10

I have created an event in one process and to test, sent the event handle via a pipe to a totally separate process (not a child thread)

When I fire the event in the firs

2条回答
  •  清歌不尽
    2021-02-06 09:37

    Yes this works:

      #COMPILE EXE "NamedEvent.exe"
    
      #INCLUDE "win32api.inc" 
    
      %EVENT_ALL_ACCESS = &h0001F0003
    
      FUNCTION PBMAIN() AS LONG  
    
        LOCAL lRet AS LONG, lError AS LONG, lEventName AS ASCIIZ * %MAX_PATH
        lEventName = "TestEvent"
        lRet   = CreateEvent (BYVAL %NULL, %False, %False, lEventName)
        lError = GetLastError ()
        IF ISFALSE lRet THEN
          MSGBOX "Unable to create Event, error:" + STR$(lError),,"CreateEvent error"
        ELSE
          IF lError = %ERROR_ALREADY_EXISTS THEN
            lRet = OpenEvent(BYVAL %EVENT_ALL_ACCESS, %False, lEventName)
            lError = GetLastError()
            IF lRet THEN
              MSGBOX "Opened existing Event, handle:" + STR$(lRet),,"OpenEvent:"
            ELSE
              MSGBOX "Unable to open Event, error:" + STR$(lError),,"OpenEvent error" : EXIT FUNCTION
            END IF
          ELSE
            MSGBOX "Created new Event, handle:" + STR$(lRet),,"CreateEvent:"
          END IF
        END IF    
    
      END FUNCTION
    

    In general, what has a lower overhead:

    Pipes (assuming small size specified)

    MemMapFiles

    Events

提交回复
热议问题