Unit mdMailSlot

.................................................................. // mdMailSlot // Copyright © 1997-98 by Martin Djernæs // .................................................................. Initial Date : 2th April 1997 Version 1.0 : 3th April 1997 8th April 1997 : + SendBufToMailSlot added 13th April 1997 : + WaitThread added for signaling that a message is arrived - TmdAutoMailSlot (substituted by TmdMailSlot) ...not installed by default, but just remove the (**) arund the Class in the Register procedure in the buttom of the unit ...The class still exists, but with a new source. 17th April 1997 : + TmdCustomWinPopup class added ...with a easy message event and a send function + TmdWinPopup class added Version 1.1 : 17th April 1997 19th Maj 1997 + Sleep in MailSlotWaitThread (Thanks to Matt Behrens) Version 1.2 : 10th Juli 1997 28th July 1997 % The paramerters in TwpMessage got new names - there were a naming conflict (Thanks to Channing Corn for reminding me) Version 1.3 : 28th Juli 1997 23th September 1997 - Two wait threads is one to many ! 24th October 1997 + Added success return value in SendBufToMailSlot (Alexander Orlov) + Added safe load of value at startup (AO + MD) Version 1.4 : 24th October 1997 + TmdCustomSecureMail + TmdSecureMail added (prevent duplicates and guarantee is integrity with a CRC16 + SendSecureMail function added Version 1.5 : 15th November 1997 % Changed the MOD 10000 to $10000, which gives 4 digits in hex! 3th January 1998 - Set of FActive removed in SetActive. (David Novak) 3th January 1998 % Changed the format of a secure mail to UNIQUE,CRC,DATA and only the UNIQUE and CRC data is stored in last message. + Added ramdom to the GetTickCount in SendSecureMail(Buf) else to mails (which are alike) send within 1 ms would be counted as equal (Idea from Alexander Orlov - AO). + SetSlot and SetServer is now made incase sensitive since mailslot names not is case sensiteive. + A SendToWinpopup is added, and the send function in the TmdCustomWinpoup now uses that one. Version 1.6 : 3th February 1998 12th March 1998 + Added FreeOnTerminate = True for the TmdMailSlotWaitThread (Thanks to Marian Maier) + TmdCustomWinPopup now have implementet an "ignore dublicatet messages" (should this be offered via a property ?) So now no messages is received double. (Thanks to David Adam Mathew for asking about the problem so I startet thinking about it) Version 1.7 : 10th April 1998 21th April 1998 + Added use of the local variable in TmdCustomWinPopup.DoMessageAvail (Thanks to Alek Shamrai) Version 1.8 : 21th April 1998 24th April 1998 % Added typecast to send secure mail (prefix got 8 bytes long when the random value became $80000000 or bigger) (Thanks to Raoul De Kezel for informing me about the problem) Version 1.9 : 24th April 1998 3th May 1998 % Typecast in SendBufSecure is now correct (do nover use two functions for the same work) - Thanks to Don Hass ;-) 7th May 1998 % The wait thread do not poll on incomming messages any longer, but uses the fact that ReadFile do only return after "timeout" milliseconds. With "timeout" set to MAILSLOT_WAIT_FOREVER the read function (dummy) do not return before there is data to read. % Wait thread got priority lowest (one more than before), since it now do not poll at incomming data anymore. Version 1.10 (1.a) : 9th May 1998 ..................................................................

Classes

TmdCustomMailSlot - .
TmdCustomSecureMail - .
TmdCustomWinPopup - For backward compatibility Removed now when the TmdCustomMailSlot have a WaitThread build in! (* TmdAutoMailSlot = Class(TmdMailSlot) Private FTimer : TTimer; FMessageList : TStringList; FMessageAvail : TmsMessageAvail; Procedure TimerProc(Sender : TObject); Protected Procedure AddMessage(Const Msg : String); Function GetMessage : String; Procedure DoMessageAvail(Const Msg : String); Virtual; Public Constructor Create(AOwner : TComponent); Override; Procedure Open; Override; Procedure Close; Override; Published Property OnMessageAvail : TmsMessageAvail Read FMessageAvail Write FMessageAvail; end; *) .
TmdMailSlot - .
TmdMailSlotWaitThread - .
TmdSecureMail - .
TmdWinPopup - .

Functions

Register - .
SendBufSecure - Format from version 1.
SendBufToMailSlot - Everthing went good
SendSecureMail - Send with preample for preventing duplicate messages, and a CRC16 for preventing errors in the data.
SendToMailSlot - .
SendToWinpopup - Sends a message to the messgr mailslot (winpopup) Hier must a sender and reciever name be given.

Types

TmsMessageAvail
TwpMessage

Constants

msDefActive
msDefMaxSize
msDefServer
msDefSlot
sBadName
sCantOpen
sExists
sGetMailSlotInfoError
sNoMessages
sNotActive
sReadError
wpSlot

Variables


Functions


procedure Register;

......................................................... Register .........................................................

Function SendBufSecure(Const Server, Slot : String; Data : PChar; Length : Integer) : Boolean;

Format from version 1.5 Mail := IntToHex(GetTickCount MOD $10000,4)+Mail; Mail := Mail + IntToHex(CalcCRC16(Mail,Length(Mail)),4); // Ver 1.6 // Format changed // Random added for improving the uniquenes

Function SendBufToMailSlot(Const Server, Slot : String; Data : PChar; Length : Integer) : Boolean;

Everthing went good

Function SendSecureMail(Const Server, Slot : String; Mail : String) : Boolean;

Send with preample for preventing duplicate messages, and a CRC16 for preventing errors in the data.

Format in version 1.5 : 4 byte TickCount as HEX Data 4 byte CRC16 Format in version 1.6 : 4 byte TickCount as HEX -| <- Now I only need to store and 4 byte CRC16 -| compare these 8 bytes Data


Function SendToMailSlot(Const Server, Slot, Mail : String) : Boolean;

......................................................... Functions ......................................................... Send a single message to a mailslot If Server is "." then the current machine are used If Server is "*" then the current domain are used

MailSlot string


Function SendToWinpopup(Server, Reciever, Sender, Msg : String) : Boolean;

Sends a message to the messgr mailslot (winpopup) Hier must a sender and reciever name be given...

Alexander Orlov - ver 1.4


Types


TmsMessageAvail = Procedure (Sender : TObject; Msg : String) of Object
......................................................... Component types .........................................................
TwpMessage = Procedure (Sender : TObject; AReciever, ASender, AMsg : String) Of Object

Constants

msDefActive = False

Default values

msDefMaxSize = 0

msDefServer = '.'

msDefSlot = 'mdMailSlot1'

sBadName = 'Bad mailslot name'

sCantOpen = 'Cannot open mailslot'

Missing constant! Error strings

sExists = 'Mailslot allready exists'

sGetMailSlotInfoError = 'Error in GetMailSlotInfo'

sNoMessages = 'No messages waiting'

sNotActive = 'Not active'

sReadError = 'Error reading message'

wpSlot = 'messngr'


Variables