1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | PROGRAM PLC_PRG VAR uiCounter : UINT; // the value-buffer where to copy from shm goes to uiSharedMemorySize : UINT := SIZEOF(uiCounter) (* 2 bytes *); pabSharedMemory : POINTER TO ARRAY[0..(64-1)] OF BYTE (* pointer to shared memory *) ; xDeleteShm : BOOL; // triggers deleting shared memory END_VAR IF hSharedMemory = RTS_INVALID_HANDLE THEN // not open. so create or open ulPhysicalAddress := 0 (* NULL means OS can choose *), pulSize := ADR(uiSharedMemorySize), pResult := ADR(result)); IF result = Errors.ERR_DUPLICATE (* from CmpErrors *) THEN xShmAlreadyExisted := TRUE; ELSE xShmAlreadyExisted := FALSE; END_IF END_IF IF hSharedMemory <> RTS_INVALID_HANDLE THEN uiBytesWritten := SysSharedMemoryWrite( hShm := hSharedMemory, ulOffset := 0, pbyData := ADR(uiCounter), ulSize := SIZEOF(uiCounter), pResult := ADR(result)); IF xDeleteShm THEN SysSharedMemoryDelete(hShm:=hSharedMemory); hSharedMemory := SINT_TO_DWORD(-1); |