Форум: "Сети";
Текущий архив: 2004.11.21;
Скачать: [xml.tar.bz2];
ВнизНарод срочно нужен компонет для работы на Маэл слотах, помогите!! Найти похожие ветки
← →
Alexander_PK (2004-09-10 15:25) [0]Не где не могу в инете найти :((
← →
Rouse_ © (2004-09-10 20:45) [1]Зачем тебе компонент?
Тут все просто:
Вот отправка:procedure TForm1.Button1Click(Sender: TObject);
var
MSHandle: THandle;
MSMessage: array [0..2] of String;
ResultMsMessage: String;
MSWrite: DWORD;
ServerName: String;
begin
ServerName := Edit1.Text;
if ServerName = "" then ServerName := "*\";
if ServerName[Length(ServerName)] <> "\" then ServerName := ServerName + "\";
MSHandle := CreateFile(PChar("\\" + ServerName + "mailslot\messngr"),
GENERIC_WRITE, // or GENERIC_READ,
FILE_SHARE_READ,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if not Win32Check(MSHandle <> INVALID_HANDLE_VALUE) then Exit;
MSMessage[0] := Edit2.Text;
MSMessage[1] := Edit3.Text;
MSMessage[2] := Memo1.Text;
CharToOem(PChar(MSMessage[0]), PChar(MSMessage[0]));
CharToOem(PChar(MSMessage[1]), PChar(MSMessage[1]));
CharToOem(PChar(MSMessage[2]), PChar(MSMessage[2]));
ResultMsMessage := MSMessage[0] + #0 + MSMessage[1] + #0 + MSMessage[2];
WriteFile(MSHandle, Pointer(PChar(ResultMsMessage))^, Length(ResultMsMessage), MSWrite, nil);
Win32Check(MSWrite = Length(ResultMsMessage));
CloseHandle(MSHandle);
end;
Вот прием:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Memo1: TMemo;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
public
MailSlot: THandle;
ErrStr: array [0..MAX_PATH] of Char;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var
CurrentSize, Size, Count: DWORD;
Msg: String;
Err: LongBool;
I: Integer;
From, sTo: String;
buf: DWORD;
begin
Count := 0;
Err := GetMailSlotInfo(MailSlot, @buf, Size, @Count, nil);
if not Err then
begin
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
nil,
GetLastError,
0,
@ErrStr[0],
MAX_PATH,
nil);
Memo1.Lines.Add("Can not GetMailSlotInfo: " + String(ErrStr));
Exit;
end;
if Count > 0 then
begin
SetLength(Msg, Size);
ReadFile(MailSlot, Msg[1], Size, CurrentSize, nil);
I := 1;
while (Msg[I] <> #0) do Inc(I);
From := Copy(Msg, 1, I - 1);
Delete(Msg, 1, I);
I := 1;
while (Msg[I] <> #0) do Inc(I);
sTo := Copy(Msg, 1, I - 1);
Delete(Msg, 1, I);
OemToChar(PChar(From), PChar(From));
OemToChar(PChar(sTo), PChar(sTo));
OemToChar(PChar(Msg), PChar(Msg));
Memo1.Lines.Add("Получено сообщение от: " + From +
" для " + sTo + #13#10 + Msg + IntToStr(CurrentSize));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MailSlot := CreateMailslot("\\.\mailslot\messngr", 0, MAILSLOT_WAIT_FOREVER, nil);
if MailSlot = INVALID_HANDLE_VALUE then
begin
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
nil,
GetLastError,
0,
@ErrStr[0],
MAX_PATH,
nil);
Memo1.Lines.Add("Can not create mailslot: " + String(ErrStr));
Exit;
end;
end;
end.
Страницы: 1 вся ветка
Форум: "Сети";
Текущий архив: 2004.11.21;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.044 c