
Originally Posted by
mvuori
I don't understand either, but I do not see any reference to WaitForSingleObject in the C++ source.
no, haven't you read my source code attach ???
#include "threadwaitforaddgroupevent.h"
ThreadWaitForAddGroupEvent::ThreadWaitForAddGroupEvent()
{
hEvent = CreateEventA(NULL, FALSE, FALSE, EVENT_ADD_NEW_GROUP);
hMapFile = CreateFileMappingA(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // max. object size
BUF_SIZE, // buffer size
MAP_FILE_ADD_NEW_GROUP); // name of mapping object
if (hMapFile == NULL)
{
return ;
}
}
void ThreadWaitForAddGroupEvent::ProcessDataFromMapFile()
{
HANDLE hMapFile = OpenFileMappingA(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
MAP_FILE_ADD_NEW_GROUP); // name of mapping object
if (hMapFile == NULL)
{
return ;
}
char *pBuf = (char*) MapViewOfFile(
hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
return ;
}
QList<QString> lUserNewGroup = dataFromMapFile.split('|');
emit AddNewGroup(lUserNewGroup);
}
void ThreadWaitForAddGroupEvent::run(){
while(1){
WaitForSingleObject(hEvent, INFINITE);
ProcessDataFromMapFile();
}
}
ThreadWaitForAddGroupEvent::~ThreadWaitForAddGroupEvent(){
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
}
#include "threadwaitforaddgroupevent.h"
ThreadWaitForAddGroupEvent::ThreadWaitForAddGroupEvent()
{
hEvent = CreateEventA(NULL, FALSE, FALSE, EVENT_ADD_NEW_GROUP);
hMapFile = CreateFileMappingA(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // max. object size
BUF_SIZE, // buffer size
MAP_FILE_ADD_NEW_GROUP); // name of mapping object
if (hMapFile == NULL)
{
return ;
}
}
void ThreadWaitForAddGroupEvent::ProcessDataFromMapFile()
{
HANDLE hMapFile = OpenFileMappingA(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
MAP_FILE_ADD_NEW_GROUP); // name of mapping object
if (hMapFile == NULL)
{
return ;
}
char *pBuf = (char*) MapViewOfFile(
hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
return ;
}
QString dataFromMapFile(pBuf);
QList<QString> lUserNewGroup = dataFromMapFile.split('|');
emit AddNewGroup(lUserNewGroup);
}
void ThreadWaitForAddGroupEvent::run(){
while(1){
WaitForSingleObject(hEvent, INFINITE);
ProcessDataFromMapFile();
}
}
ThreadWaitForAddGroupEvent::~ThreadWaitForAddGroupEvent(){
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
}
To copy to clipboard, switch view to plain text mode
SendEvent:
#include <QtCore/QCoreApplication>
#include <QtGui/QMessageBox>
#include <QString>
#include <windows.h>
#define BUF_SIZE 1024
#define MAP_FILE_ADD_NEW_GROUP "Local\\MyFileMappingAddNewGroup"
#define EVENT_ADD_NEW_GROUP "Local\\eventaddnewgroup"
int main(int argc, char *argv[])
{
HANDLE hMapFile;
char* pBuf;
QString qstrDataSend
= "ADDKJHGFDSDFGHJ";
hMapFile = OpenFileMappingA(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
MAP_FILE_ADD_NEW_GROUP); // name of mapping object
if (hMapFile == NULL)
{
QMessageBox::information( NULL,
"L?i ph?n m?m",
"L?i OpenFileMapping, B?n hãy kh?i d?ng l?i ph?n m?m" );
return 1;
}
pBuf = (char*) MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
QMessageBox::information( NULL,
"loi",
"khong the map view file" );
return 2;
}
CopyMemory((PVOID) pBuf, qstrDataSend.toStdString().data(), qstrDataSend.length());
HANDLE hEvent = OpenEventA(EVENT_ALL_ACCESS, FALSE, EVENT_ADD_NEW_GROUP);
SetEvent(hEvent);
return a.exec();
}
#include <QtCore/QCoreApplication>
#include <QtGui/QMessageBox>
#include <QString>
#include <windows.h>
#define BUF_SIZE 1024
#define MAP_FILE_ADD_NEW_GROUP "Local\\MyFileMappingAddNewGroup"
#define EVENT_ADD_NEW_GROUP "Local\\eventaddnewgroup"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
HANDLE hMapFile;
char* pBuf;
QString qstrDataSend = "ADDKJHGFDSDFGHJ";
hMapFile = OpenFileMappingA(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
MAP_FILE_ADD_NEW_GROUP); // name of mapping object
if (hMapFile == NULL)
{
QMessageBox::information( NULL, "L?i ph?n m?m","L?i OpenFileMapping, B?n hãy kh?i d?ng l?i ph?n m?m" );
return 1;
}
pBuf = (char*) MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
QMessageBox::information( NULL, "loi","khong the map view file" );
return 2;
}
CopyMemory((PVOID) pBuf, qstrDataSend.toStdString().data(), qstrDataSend.length());
HANDLE hEvent = OpenEventA(EVENT_ALL_ACCESS, FALSE, EVENT_ADD_NEW_GROUP);
SetEvent(hEvent);
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks