Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2002.05.20;
Скачать: [xml.tar.bz2];

Вниз

MAIL SLOTS   Найти похожие ветки 

 
o_viz2000   (2002-03-16 21:43) [0]

Подскажите как нормально работать с mail slots, т.е. открывать к ним доступ, писать и читать. Меня че-то заклинило
Заранее благодарен


 
VuDZ   (2002-03-17 06:52) [1]

Creating a Mailslot
Mailslots are supported by three specialized functions: CreateMailslot, GetMailslotInfo, and SetMailslotInfo. These functions are used by the mailslot server.

The following code sample uses the CreateMailslot function to retrieve the handle to a mailslot named sample_mailslot.

BOOL FAR PASCAL Makeslot(HWND hwnd, HDC hdc)
{
LPSTR lpszSlotName = "\\\\.\\mailslot\\sample_mailslot";

// The mailslot handle "hSlot1" is declared globally.

HANDLE hSlot1 = CreateMailslot(lpszSlotName,
0, // no maximum message size
MAILSLOT_WAIT_FOREVER, // no time-out for operations
(LPSECURITY_ATTRIBUTES) NULL); // no security attributes

if (hSlot1 == INVALID_HANDLE_VALUE)
{
ErrorHandler(hwnd, "CreateMailslot"); // local error handler
return FALSE;
}

TextOut(hdc, 10, 10, "CreateMailslot successful.", 26);
return TRUE;
}

To create a mailslot that can be inherited by child processes, an application should change the SECURITY_ATTRIBUTES structure passed as the last parameter of CreateMailslot. To do this, the application sets the bInheritHandle member of this structure to TRUE (the default setting is FALSE).

ещё сть примеры Writing to a Mailslot & Reading from a Mailslot нужно?


 
o_viz2000   (2002-03-17 09:00) [2]

Как раз это и интересует. Спасибо за ответ Буду рад дальнейшей помощи


 
VuDZ   (2002-03-17 09:54) [3]

Writing to a Mailslot
Writing to a mailslot is similar to writing to a standard disk file. The following code uses the CreateFile, WriteFile, and CloseHandle functions to put a short message in a mailslot. The message is broadcast to every computer in the primary domain of the system.


LPSTR lpszMessage = "Message for sample_mailslot in primary domain.";
BOOL fResult;
HANDLE hFile;
DWORD cbWritten;

hFile = CreateFile("\\\\*\\mailslot\\sample_mailslot",
GENERIC_WRITE,
FILE_SHARE_READ, // required to write to a mailslot
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);

if (hFile == INVALID_HANDLE_VALUE)
{
ErrorHandler(hwnd, "Primary domain"); // local error handler
return FALSE;
}

fResult = WriteFile(hFile,
lpszMessage,
(DWORD) lstrlen(lpszMessage) + 1, // include terminating null
&cbWritten,
(LPOVERLAPPED) NULL);

if (!fResult)
{
ErrorHandler(hwnd, "WriteFile");
return FALSE;
}

TextOut(hdc, 10, 10, "WriteFile successful.", 21);

fResult = CloseHandle(hFile);

if (!fResult)
{
ErrorHandler(hwnd, "CloseHandle");
return FALSE;
}

TextOut(hdc, 10, 30, "CloseHandle successful.", 23);
return TRUE;


 
VuDZ   (2002-03-17 09:56) [4]

Reading from a Mailslot
The process that creates a mailslot can read messages from it by using the mailslot handle in a call to the ReadFile function. The code in the following example calls the GetMailslotInfo function to determine whether there are messages in the mailslot. If messages are waiting, each is displayed in a message box along with the number of messages remaining to be read.

A mailslot exists until the CloseHandle function is called for all open server handles or until all server processes that own a mailslot handle exit. In both cases, any unread messages are deleted from the mailslot, all client handles to the mailslot are closed, and the mailslot itself is deleted from memory.


BOOL WINAPI Readslot(HWND hwnd, HDC hdc)
{
DWORD cbMessage, cMessage, cbRead;
BOOL fResult;
LPSTR lpszBuffer;
CHAR achID[80];
DWORD cAllMessages;
HANDLE hEvent;
OVERLAPPED ov;

cbMessage = cMessage = cbRead = 0;

hEvent = CreateEvent(NULL, FALSE, FALSE, "ExampleSlot");
ov.Offset = 0;
ov.OffsetHigh = 0;
ov.hEvent = hEvent;

// Mailslot handle "hSlot1" is declared globally.

fResult = GetMailslotInfo(hSlot1, // mailslot handle
(LPDWORD) NULL, // no maximum message size
&cbMessage, // size of next message
&cMessage, // number of messages
(LPDWORD) NULL); // no read time-out

if (!fResult)
{
ErrorHandler(hwnd, "GetMailslotInfo");
return FALSE;
}

if (cbMessage == MAILSLOT_NO_MESSAGE)
{
TextOut(hdc, 10, 10, "No waiting messages.", 20);
return TRUE;
}

cAllMessages = cMessage;

while (cMessage != 0) // retrieve all messages
{
// Create a message-number string.

wsprintf((LPSTR) achID,
"\nMessage #%d of %d\n", cAllMessages - cMessage + 1,
cAllMessages);

// Allocate memory for the message.

lpszBuffer = (LPSTR) GlobalAlloc(GPTR,
lstrlen((LPSTR) achID) + cbMessage);

lpszBuffer[0] = "\0";

fResult = ReadFile(hSlot1,
lpszBuffer,
cbMessage,
&cbRead,
&ov);

if (!fResult)
{
ErrorHandler(hwnd, "ReadFile");
GlobalFree((HGLOBAL) lpszBuffer);
return FALSE;
}

// Concatenate the message and the message-number string.

lstrcat(lpszBuffer, (LPSTR) achID);

// Display the message.

MessageBox(hwnd,
lpszBuffer,
"Contents of Mailslot",
MB_OK);

GlobalFree((HGLOBAL) lpszBuffer);

fResult = GetMailslotInfo(hSlot1, // mailslot handle
(LPDWORD) NULL, // no maximum message size
&cbMessage, // size of next message
&cMessage, // number of messages
(LPDWORD) NULL); // no read time-out

if (!fResult)
{
ErrorHandler(hwnd, "GetMailslotInfo");
return FALSE;
}
}
return TRUE;
}

Microsoft Platform SDK, February 2001 Edition.
This content last built on Wednesday, February 07, 2001.


 
o_viz2000   (2002-03-17 21:54) [5]

Уважаемые мастаки и снова тот же вопрос, но более конкретно

создается класс по работе с mail slots.
В конструкторе класса создается mail slot:

FSlotName:="\\.\mailslot\SlotTestName";
FSlotHandle:=CreateMailslot(FSlotName,FMaxMsgSize,
MAILSLOT_WAIT_FOREVER,NIL);
if FSlotHandle=INVALID_HANDLE_VALUE then
RaiseLastWin32Error;

В другом методе mail slot открывается как файл:

FSlotName:="\\*\mailslot\SlotTestName";
FFileHandle:=CreateFile(FSlotName,
GENERIC_READ,
FILE_SHARE_READ,
NIL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
{ ****** } if FFileHandle=INVALID_HANDLE_VALUE then
RaiseLastWin32Error;
так вот в помеченной строке возникает исключение с
кодом 87 "Неверный параметр".
Я уже запарился по всей видимости, но уже бьюсь,
так что буду благодарен за любую помощь.


 
VuDZ   (2002-03-17 22:53) [6]

попробуй использовать чистый HANDLE, я просто взял, объединил первых 2 примера в один - всё заработало...

PS FSlotNmae дб PChar, но не оканчиваться нулём


 
o_viz2000   (2002-03-18 00:24) [7]

Извините но не понял что означает чистый HANDLE

после объединения процедур создания mailslot и файла все та же ошибка ("Неверный параметр")


 
VuDZ   (2002-03-18 01:50) [8]

т.е. использовать 32х битную переменную. но это лирика.
Мне кажется, что проблема в имени - приведи исходник, а то я не гадалка...

PS если результат OpenFile HANDLE не равно 0xffffffff, то ошибки нет


 
kull   (2002-03-18 13:39) [9]

Удалено модератором



Страницы: 1 вся ветка

Форум: "WinAPI";
Текущий архив: 2002.05.20;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.056 c
1-64710
demon-777
2002-05-06 18:04
2002.05.20
Как скрыть и показать курсор


1-64747
3asys
2002-05-07 11:57
2002.05.20
Работа с объектами


3-64502
vopros
2002-04-22 13:37
2002.05.20
Где найти компонент DBTree?Бесплатный.


4-64886
socket
2002-03-15 22:11
2002.05.20
Хук на GETMESSAGE


3-64529
Vasilii
2002-04-22 15:44
2002.05.20
проблемы с IBEvents?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский