Click here to Skip to main content
16,017,015 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: FileMapping book exmple goes in loop Pin
coco2438-Aug-22 11:45
coco2438-Aug-22 11:45 
GeneralRe: FileMapping book exmple goes in loop Pin
Mircea Neacsu8-Aug-22 11:47
Mircea Neacsu8-Aug-22 11:47 
Questiondefining a function with #define Pin
coco24330-Jul-22 9:03
coco24330-Jul-22 9:03 
AnswerRe: defining a function with #define Pin
Mircea Neacsu30-Jul-22 9:54
Mircea Neacsu30-Jul-22 9:54 
GeneralRe: defining a function with #define Pin
trønderen30-Jul-22 12:46
trønderen30-Jul-22 12:46 
GeneralRe: defining a function with #define Pin
Greg Utas30-Jul-22 13:58
professionalGreg Utas30-Jul-22 13:58 
AnswerRe: defining a function with #define Pin
Randor 30-Jul-22 9:55
professional Randor 30-Jul-22 9:55 
GeneralRe: defining a function with #define Pin
coco2433-Aug-22 9:01
coco2433-Aug-22 9:01 
QuestionHow to read an xlsx file using CDatabase Pin
Sampath57927-Jul-22 19:54
Sampath57927-Jul-22 19:54 
AnswerRe: How to read an xlsx file using CDatabase Pin
Victor Nijegorodov27-Jul-22 20:07
Victor Nijegorodov27-Jul-22 20:07 
GeneralRe: How to read an xlsx file using CDatabase Pin
Sampath57931-Jul-22 23:27
Sampath57931-Jul-22 23:27 
GeneralRe: How to read an xlsx file using CDatabase Pin
Richard MacCutchan31-Jul-22 23:38
mveRichard MacCutchan31-Jul-22 23:38 
AnswerMessage Closed Pin
31-Jul-22 17:19
Sampath57931-Jul-22 17:19 
GeneralRe: How to read an xlsx file using CDatabase Pin
Dave Kreskowiak31-Jul-22 17:30
mveDave Kreskowiak31-Jul-22 17:30 
GeneralRe: How to read an xlsx file using CDatabase Pin
Sampath57931-Jul-22 23:40
Sampath57931-Jul-22 23:40 
GeneralRe: How to read an xlsx file using CDatabase Pin
Sampath5791-Aug-22 23:21
Sampath5791-Aug-22 23:21 

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.