void Sever()
{
SecondStruct *pSecond = NULL;
HANDLE hEvent = CreateEvent(
NULL, // default security attributes
TRUE, // manual-reset event
FALSE, // initial state is nonsignaled
TEXT("WriteEvent") // object name
);
if (hEvent == NULL) {
return;
}
for (;;)
{
HANDLE hMapFile = CreateFileMapping((HANDLE)INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,0, sizeof(SecondStruct), NAMESECONDSTRUCT);
if (hMapFile == NULL)
{
return ;
}
pSecond = (SecondStruct *) MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
sizeof(SecondStruct));
if (pSecond == NULL)
{
CloseHandle(hMapFile);
return;
}
memset(pSecond, 0, sizeof(pSecond));
DWORD dwWaitResult = WaitForSingleObject(
hEvent, // event handle
INFINITE); // indefinite wait
switch (dwWaitResult)
{
// Event object was signaled
case WAIT_OBJECT_0:
//
// TODO: Read from the shared buffer
//
lSeconds = 0;
lSeconds = pSecond->lSecond;
//do sth
....
....
....
UnmapViewOfFile(pSecond);
CloseHandle(hMapFile);
break;
// An error occurred
default:
return;
}
}
//
void custume()
{
HANDLE hMapFile = CreateFileMapping((HANDLE)INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,0, sizeof(SecondStruct), NAMESECONDSTRUCT);
if (hMapFile == NULL)
{
return ;
}
SecondStruct *pSecond = NULL;
pSecond = (SecondStruct *) MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
sizeof(SecondStruct));
if (pSecond == NULL)
{
CloseHandle(hMapFile);
return;
}
memset(pSecond, 0, sizeof(pSecond));
pSecond->lSecond = m_szSecond;
UnmapViewOfFile(pSecond);
CloseHandle(hMapFile);
HANDLE hEvent = CreateEvent(
NULL, // default security attributes
TRUE, // manual-reset event
FALSE, // initial state is nonsignaled
TEXT("WriteEvent") // object name
);
SetEvent(hEvent);
}