Click here to Skip to main content
15,914,594 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Status Bar Help Required Pin
toxcct12-May-04 7:25
toxcct12-May-04 7:25 
GeneralRe: Status Bar Help Required Pin
vividtang13-May-04 15:41
vividtang13-May-04 15:41 
GeneralC++ Exception Handling Pin
IceBerG7112-May-04 5:41
IceBerG7112-May-04 5:41 
GeneralRe: C++ Exception Handling Pin
David Crow12-May-04 6:36
David Crow12-May-04 6:36 
GeneralRe: C++ Exception Handling Pin
IceBerG7112-May-04 15:30
IceBerG7112-May-04 15:30 
GeneralRe: C++ Exception Handling Pin
Joe Woodbury12-May-04 7:08
professionalJoe Woodbury12-May-04 7:08 
GeneralRe: C++ Exception Handling Pin
Paul Ranson12-May-04 13:11
Paul Ranson12-May-04 13:11 
GeneralEvents and Shared Memory Pin
sweep12312-May-04 4:57
sweep12312-May-04 4:57 
I have a libray which sets up shared memory and an event to
schedule some processing (display data, quite larger) in a GUI (a separate thread in the GUI will process this event).

All works fine if I use timers to do the display of the data, however if I opt for Events then the Shared Memory pointer 'm_pMsg' goes invalid following the first event.
So Shared Memory does not work with Events - Am I missing something

Could someone have a good at the code sections below and see if this scheme is correct

In the Library (Loaded DLL)

m_hMap = ::CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0,
sizeof(TSharedMemory),
"CSLSharedMem");

// Obtain a pointer from the handle to file mapping object
m_pMsg = (TSharedMemory*)::MapViewOfFile(m_hMap,FILE_MAP_WRITE,0,0,sizeof(TSharedMemory));

// Set up an event for the GUI to process the Display Text
hGlobalWriteEvent = CreateEvent(NULL, // no security attributes
TRUE, // manual-reset event
FALSE, // initial state is signaled
"CSLDisplayData" // object name
);
// Signal GUI to process this request
::SetEvent(hGlobalWriteEvent);


Now in the GUI (Main)

// Try to create file mapping object (assume that this is the server)
m_hMap = ::CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0,
sizeof(TSharedMemory),
"CSLSharedMem");
// Check if file mapping object already exists. If it does, then this is a
// client and in this case open existing file mapping object. Client also
// needs to create a mutex object to synchronize access to the server
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
m_hMap = ::OpenFileMapping(FILE_MAP_WRITE,FALSE,"CSLSharedMem");
m_strOutput+= "File Already Exists - This is the Client " + crlf;
SetDlgItemText(IDC_OUTPUT, m_strOutput);
UpdateData();

}
else
{
MessageBox("File Mappings Hove Not Been Setup - Check WHLLIB.DLL");
m_strOutput+= "Warning - This is the Server " + crlf;
SetDlgItemText(IDC_OUTPUT, m_strOutput);
UpdateData();
}
// Obtain a pointer from the handle to file mapping object
m_pMsg = (TSharedMemory*)::MapViewOfFile(m_hMap,FILE_MAP_WRITE,0,0,sizeof(TSharedMemory));


In the GUI Thread

UINT CTestGUI1Dlg::DisplayTextThread(LPVOID param)
{
/* This is the thread function for the Display Data. The structure contains a stop flag and the 'this'
pointer for access to the dialog properties. */

DisplayThreadData* ThreadData = (DisplayThreadData*)param;

CTestGUI1Dlg* pxDlg = (CTestGUI1Dlg*) ThreadData->_this; // (CMyDialog*) pxDlg = (CMyDialog*) pParam;

// Set up an event for the GUI to process the Display Text
hGlobalWriteEvent = CreateEvent(NULL, // no security attributes
TRUE, // manual-reset event
FALSE, // initial state is signaled
"CSLDisplayData" // object name
);
while(!ThreadData->stopFlag)
{
if (::WaitForSingleObject(hGlobalWriteEvent, INFINITE) == WAIT_OBJECT_0)
{
// AfxMessageBox("Event Fired");
pxDlg->UpdateOutput();
}
}

return 0;
}

Help
GeneralRe: Events and Shared Memory Pin
Joe Woodbury12-May-04 6:58
professionalJoe Woodbury12-May-04 6:58 
GeneralRe: Events and Shared Memory Pin
Grahamfff12-May-04 9:56
Grahamfff12-May-04 9:56 
GeneralRe: Events and Shared Memory Pin
Joe Woodbury12-May-04 10:23
professionalJoe Woodbury12-May-04 10:23 
QuestionWhere can I find some article about technique of VC++ IDE? Pin
bloggs197412-May-04 4:47
bloggs197412-May-04 4:47 
AnswerRe: Where can I find some article about technique of VC++ IDE? Pin
jmkhael12-May-04 4:54
jmkhael12-May-04 4:54 
GeneralThank you, it is. Do anyone has more? Pin
bloggs197412-May-04 8:42
bloggs197412-May-04 8:42 
GeneralMJPEG question Pin
cristane12-May-04 4:45
cristane12-May-04 4:45 
GeneralRe: MJPEG question Pin
Chris Losinger12-May-04 4:59
professionalChris Losinger12-May-04 4:59 
GeneralHelp for mschart problem! Pin
allen_homer12-May-04 4:35
allen_homer12-May-04 4:35 
GeneralConversion from integer to string Pin
jazzlycool12-May-04 4:08
jazzlycool12-May-04 4:08 
GeneralRe: Conversion from integer to string Pin
jmkhael12-May-04 4:14
jmkhael12-May-04 4:14 
GeneralRe: Conversion from integer to string Pin
bikram singh12-May-04 4:25
bikram singh12-May-04 4:25 
GeneralRe: Conversion from integer to string Pin
jazzlycool12-May-04 4:56
jazzlycool12-May-04 4:56 
GeneralRe: Conversion from integer to string Pin
Rafael Fernández López12-May-04 11:04
Rafael Fernández López12-May-04 11:04 
GeneralisValidDoubleValue(double *) Pin
Tibor Blazko12-May-04 3:58
Tibor Blazko12-May-04 3:58 
GeneralRe: isValidDoubleValue(double *) Pin
jmkhael12-May-04 4:20
jmkhael12-May-04 4:20 
GeneralRe: isValidDoubleValue(double *) Pin
Tibor Blazko12-May-04 4:22
Tibor Blazko12-May-04 4:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.