Click here to Skip to main content
15,903,856 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: #define won't work in QStringList , gives no error Pin
David Crow11-Aug-22 16:03
David Crow11-Aug-22 16:03 
Questionmanaging objects derived from the same base class using a container Pin
Calin Negru10-Aug-22 3:29
Calin Negru10-Aug-22 3:29 
AnswerRe: managing objects derived from the same base class using a container Pin
Mircea Neacsu10-Aug-22 3:55
Mircea Neacsu10-Aug-22 3:55 
AnswerRe: managing objects derived from the same base class using a container Pin
Greg Utas10-Aug-22 3:56
professionalGreg Utas10-Aug-22 3:56 
GeneralRe: managing objects derived from the same base class using a container Pin
Calin Negru10-Aug-22 6:34
Calin Negru10-Aug-22 6:34 
AnswerRe: managing objects derived from the same base class using a container Pin
Richard MacCutchan10-Aug-22 4:01
mveRichard MacCutchan10-Aug-22 4:01 
GeneralRe: managing objects derived from the same base class using a container Pin
Calin Negru10-Aug-22 6:33
Calin Negru10-Aug-22 6:33 
GeneralRe: managing objects derived from the same base class using a container Pin
Richard MacCutchan10-Aug-22 6:40
mveRichard MacCutchan10-Aug-22 6:40 
GeneralRe: managing objects derived from the same base class using a container Pin
Calin Negru10-Aug-22 11:14
Calin Negru10-Aug-22 11:14 
GeneralRe: managing objects derived from the same base class using a container Pin
k505410-Aug-22 13:01
mvek505410-Aug-22 13:01 
GeneralRe: managing objects derived from the same base class using a container Pin
Calin Negru10-Aug-22 21:25
Calin Negru10-Aug-22 21:25 
GeneralRe: managing objects derived from the same base class using a container Pin
Richard MacCutchan10-Aug-22 21:10
mveRichard MacCutchan10-Aug-22 21:10 
GeneralRe: managing objects derived from the same base class using a container Pin
Calin Negru11-Aug-22 0:38
Calin Negru11-Aug-22 0:38 
GeneralRe: managing objects derived from the same base class using a container Pin
Richard MacCutchan11-Aug-22 0:39
mveRichard MacCutchan11-Aug-22 0:39 
GeneralRe: managing objects derived from the same base class using a container Pin
Calin Negru11-Aug-22 0:57
Calin Negru11-Aug-22 0:57 
GeneralRe: managing objects derived from the same base class using a container Pin
Calin Negru12-Aug-22 18:58
Calin Negru12-Aug-22 18:58 
GeneralRe: managing objects derived from the same base class using a container Pin
Richard MacCutchan12-Aug-22 21:55
mveRichard MacCutchan12-Aug-22 21:55 
Questionmoving graphics in a win32 c++ window Pin
Calin Negru9-Aug-22 8:25
Calin Negru9-Aug-22 8:25 
AnswerRe: moving graphics in a win32 c++ window Pin
Gerry Schmitz9-Aug-22 9:15
mveGerry Schmitz9-Aug-22 9:15 
AnswerRe: moving graphics in a win32 c++ window Pin
Graham Breach9-Aug-22 20:54
Graham Breach9-Aug-22 20:54 
AnswerRe: moving graphics in a win32 c++ window Pin
Richard MacCutchan9-Aug-22 20:57
mveRichard MacCutchan9-Aug-22 20:57 
GeneralRe: moving graphics in a win32 c++ window Pin
Calin Negru10-Aug-22 1:58
Calin Negru10-Aug-22 1:58 
GeneralRe: moving graphics in a win32 c++ window Pin
Richard MacCutchan10-Aug-22 2:01
mveRichard MacCutchan10-Aug-22 2:01 
QuestionFileMapping book exmple goes in loop Pin
coco2438-Aug-22 8:48
coco2438-Aug-22 8:48 
Hi,

I am following an example from a book and it doesn't work fine.

In a win32 c++ project I am trying to make the following codes to work:

At the window creation the mapped file is created

C++
case WM_CREATE:
		{
			// Create a file mapped object.
			//.............................
			hMapFile = CreateFileMapping( (HANDLE)0xFFFFFFFF, NULL,
				                          PAGE_READWRITE, 
										  0,
										  1024,
										  "MyFileMappingObject" );

			// Return if the mapping failed.
			//..............................
			if ( !hMapFile )
				return(-1);
		}
		break;


There are made modification in mapped file in the following thread function:

C++
DWORD AnotherProcess( LPDWORD lpdwParam )
{
	HANDLE hFileMap;
	LPTSTR lpMapAddress;

	// Open the file mapping.
	//.......................
	hFileMap = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE,
		                        "MyFileMappingObject" );

	// Map a view to the mapping object.
	//..................................
	lpMapAddress =(LPTSTR)MapViewOfFileEx( hFileMap, FILE_MAP_ALL_ACCESS,
		                            0, 0, 0, lpdwParam );

	// Display the contents of the memory.
	//....................................
	MessageBox( NULL, lpMapAddress, "Mapped Memmory",
		        MB_OK | MB_ICONINFORMATION );

	// Set "Received" into the memory.
	//................................
	strcpy( lpMapAddress, "Received" );

	UnmapViewOfFile( lpMapAddress );

	return( 0 );
}


There are made modification on mapped file and the thread function is called on the following code:

C++
case IDM_TEST:
			{   
				DWORD dwID;
				// Map a view of the file mapped object.
				//......................................
				lpMapAddress = (LPTSTR)MapViewOfFile( hMapFile, 
					                          FILE_MAP_ALL_ACCESS,
											  0, 0, 0 );

				// Place data int the view.
				//.........................
				strcpy(lpMapAddress, "Data passed from main process.");

				// Make sure the data is flushed to the file.
				//...........................................
				FlushViewOfFile( lpMapAddress, 
					             lstrlen( lpMapAddress ) );

				// Create a thread to receive the data.
				//.....................................
				hThread = CreateThread( NULL, 0, 
					      (LPTHREAD_START_ROUTINE)AnotherProcess, 
						  lpMapAddress, 0, &dwID);

				// Set a timer to wait for the data to be processed.
				//..................................................
				SetTimer( hWnd, 1,	1000, NULL );
			}
			break;


If everything is ok all cycle is ended with the timer:

C++
case WM_TIMER:
		{
			// Check to see if the thread has processed the memory.
			//.....................................................
			if ( strcmp( lpMapAddress, "Received" ) == 0 )
			{
				// Kill the timer and thread.
				//...........................
				KillTimer( hWnd, 1 );
				TerminateThread( hThread, 0 );

				MessageBox( hWnd, lpMapAddress, "Done", MB_OK );

				UnmapViewOfFile( lpMapAddress );

			}


When I put breakpoint in the "AnotherProcess" thread function, after the message box, in the message box no message
is displayed, like lpMapAddress would be empty.
It could be from OpenFileMapping or MapViewOfFileEx to not doing their job? Because in watch table lpMapAddress
has value 0.

After that point, the compiler enters in a kind of assambler code in a inifinite main loop. Maybe here WM_TIMER goes crazy.

Can you help me to figure out what should be done? Where are the things that are nok?

Thank you very much.
AnswerRe: FileMapping book exmple goes in loop Pin
Mircea Neacsu8-Aug-22 10:35
Mircea Neacsu8-Aug-22 10:35 

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.