Click here to Skip to main content
13,665,440 members

C / C++ / MFC

 
GeneralRe: Condition variable question Pin
Richard MacCutchan4-Aug-18 3:19
protectorRichard MacCutchan4-Aug-18 3:19 
GeneralRe: Condition variable question Pin
focusdoit4-Aug-18 3:22
memberfocusdoit4-Aug-18 3:22 
GeneralRe: Condition variable question Pin
Richard MacCutchan4-Aug-18 3:31
protectorRichard MacCutchan4-Aug-18 3:31 
GeneralRe: Condition variable question Pin
focusdoit4-Aug-18 8:25
memberfocusdoit4-Aug-18 8:25 
GeneralRe: Condition variable question Pin
Richard MacCutchan4-Aug-18 9:32
protectorRichard MacCutchan4-Aug-18 9:32 
GeneralRe: Condition variable question Pin
focusdoit4-Aug-18 16:30
memberfocusdoit4-Aug-18 16:30 
GeneralRe: Condition variable question Pin
Richard MacCutchan4-Aug-18 20:57
protectorRichard MacCutchan4-Aug-18 20:57 
QuestionA Problem in Writing Shared Memory to windows from a C++ application Pin
D_code_writer2-Aug-18 5:00
memberD_code_writer2-Aug-18 5:00 
Hey Guys,

I'm writing an application in C++ that needs to write shared memory to windows and I've hit a stumbling block.

Even though I'm not getting any error messages (I've stepped through with the debugger) it would appear nothing is writing to shared memory. Here is the code that writes the shared memory,

void Write_Physics(PhysicsStruct *s_physics)
{
//	Create the shared memory
	TCHAR szName[] = TEXT("Local\\physics");
	hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(PhysicsStruct), szName);
	if (!hMapFile)
	{
		return;
	}

	//	Open the buffer for file read and write
	mapFileBuffer = (unsigned char*)MapViewOfFile(m_physics.hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(PhysicsStruct));
	if (!mapFileBuffer)
	{
		return;
	}
	
	//	Copy the physics pointer over
	CopyMemory(mapFileBuffer,s_physics,sizeof(PhysicsStruct));
	//_getch();
	

	//	Write the shared memory
	UnmapViewOfFile(m_physics.mapFileBuffer);
	CloseHandle(m_physics.hMapFile);
}


My difficulty is that when I try another process to read the shared memory nothing is happening. For completeness here is the code that reads the structure from the shared memory,
void Read_Physics(PhysicsStruct *s_physics)
{
	//	Create the shared memory
	TCHAR szName[] = TEXT("Local\\physics");
	hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(PhysicsStruct), szName);
	if (!m_physics.hMapFile)
	{
		return;
	}

	//	Open the buffer for file read and write
	mapFileBuffer = (unsigned char*)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, sizeof(PhysicsStruct));
	if (!mapFileBuffer)
	{
		return;
	}

	s_physics = (PhysicsStruct*)mapFileBuffer;

	//	Write the shared memory
	UnmapViewOfFile(mapFileBuffer);
	CloseHandle(hMapFile);	
}
//-----------------------------------------------------------------------


If anyone has any suggestions it would be greatly appreciated. What the problem resembles is like trying to write something to file and forgetting the fprintf or file write commands.

Thanks in advance guys.
AnswerRe: A Problem in Writing Shared Memory to windows from a C++ application Pin
Richard Andrew x642-Aug-18 13:00
professionalRichard Andrew x642-Aug-18 13:00 
AnswerRe: A Problem in Writing Shared Memory to windows from a C++ application Pin
Richard Andrew x642-Aug-18 13:06
professionalRichard Andrew x642-Aug-18 13:06 
GeneralRe: A Problem in Writing Shared Memory to windows from a C++ application Pin
D_code_writer2-Aug-18 20:24
memberD_code_writer2-Aug-18 20:24 
GeneralRe: A Problem in Writing Shared Memory to windows from a C++ application Pin
Richard Andrew x643-Aug-18 2:41
professionalRichard Andrew x643-Aug-18 2:41 
GeneralRe: A Problem in Writing Shared Memory to windows from a C++ application Pin
D_code_writer3-Aug-18 12:45
memberD_code_writer3-Aug-18 12:45 
GeneralRe: A Problem in Writing Shared Memory to windows from a C++ application Pin
Richard Andrew x643-Aug-18 13:44
professionalRichard Andrew x643-Aug-18 13:44 
GeneralRe: A Problem in Writing Shared Memory to windows from a C++ application Pin
D_code_writer3-Aug-18 14:05
memberD_code_writer3-Aug-18 14:05 
QuestionCEditCtrl in FrameWnd Pin
john56321-Aug-18 23:50
memberjohn56321-Aug-18 23:50 
AnswerRe: CEditCtrl in FrameWnd Pin
Richard MacCutchan2-Aug-18 0:35
protectorRichard MacCutchan2-Aug-18 0:35 
AnswerRe: CEditCtrl in FrameWnd Pin
Jochen Arndt2-Aug-18 0:51
mvpJochen Arndt2-Aug-18 0:51 
AnswerRe: CEditCtrl in FrameWnd Pin
Victor Nijegorodov2-Aug-18 1:01
memberVictor Nijegorodov2-Aug-18 1:01 
QuestionRun CFile::Open as admin Pin
_Flaviu1-Aug-18 21:47
member_Flaviu1-Aug-18 21:47 
AnswerRe: Run CFile::Open as admin Pin
Jochen Arndt1-Aug-18 22:54
mvpJochen Arndt1-Aug-18 22:54 
GeneralRe: Run CFile::Open as admin Pin
_Flaviu1-Aug-18 23:00
member_Flaviu1-Aug-18 23:00 
Questionexecl in c++ example Pin
Shaul.amir30-Jul-18 22:12
memberShaul.amir30-Jul-18 22:12 
AnswerRe: execl in c++ example Pin
Jochen Arndt30-Jul-18 23:02
mvpJochen Arndt30-Jul-18 23:02 
Questionhelp me~ for use..... #define macro ## #@ # Pin
dsyoon ds29-Jul-18 17:00
memberdsyoon ds29-Jul-18 17:00 

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.


Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180810.1 | Last Updated 17 Aug 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid