Click here to Skip to main content
15,919,613 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Modeless Onscreen Keyboard Pin
Rajesh R Subramanian21-Jun-11 9:52
professionalRajesh R Subramanian21-Jun-11 9:52 
QuestionRegarding Memory Mapped Pin
manju 321-Jun-11 2:52
manju 321-Jun-11 2:52 
AnswerRe: Regarding Memory Mapped Pin
«_Superman_»21-Jun-11 6:17
professional«_Superman_»21-Jun-11 6:17 
GeneralRe: Regarding Memory Mapped Pin
manju 323-Jun-11 2:39
manju 323-Jun-11 2:39 
GeneralRe: Regarding Memory Mapped Pin
enhzflep23-Jun-11 11:06
enhzflep23-Jun-11 11:06 
GeneralRe: Regarding Memory Mapped Pin
manju 323-Jun-11 20:25
manju 323-Jun-11 20:25 
GeneralRe: Regarding Memory Mapped Pin
enhzflep23-Jun-11 21:12
enhzflep23-Jun-11 21:12 
GeneralRe: Regarding Memory Mapped Pin
manju 323-Jun-11 22:19
manju 323-Jun-11 22:19 
Hi,
I tried splitting the functions as you said,but some junk values is coming in second process.
This is what i am trying to do.

In Process 1

// Procees1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>




#define BUF_SIZE 2048
char buffer[BUF_SIZE];
TCHAR szName[]=TEXT("Global\\MyFileMappingObject");
TCHAR szMsg[]=TEXT(" Read Values from first process.");
LPCTSTR pBuf;


int addMsg(char *msg)
{
long msgCount, curMsgIndex, curMsgLen;
char *newStrPos;


memcpy((PVOID)&msgCount, buffer, sizeof(long));

newStrPos = (char*) (long)&buffer + sizeof(long);

for (curMsgIndex=0; curMsgIndex<msgCount; curMsgIndex++)
{
curMsgLen = strlen(newStrPos);
newStrPos += curMsgLen + 1;
}
{
printf("adding message\n");
strcpy(newStrPos, msg);
CopyMemory((PVOID)pBuf, msg, (_tcslen(szMsg) * sizeof(TCHAR)));
msgCount++;
memcpy((PVOID)buffer, &msgCount, sizeof(long));
}

return 0;
}


int _tmain()
{
HANDLE hMapFile1;


hMapFile1 = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // maximum object size (high-order DWORD)
BUF_SIZE, // maximum object size (low-order DWORD)
szName); // name of mapping object

if (hMapFile1 == NULL)
{
_tprintf(TEXT("Could not create file mapping object (%d).\n"),
GetLastError());
return 1;
}
pBuf = (LPTSTR) MapViewOfFile(hMapFile1, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);

if (pBuf == NULL)
{
_tprintf(TEXT("Could not map view of file (%d).\n"),
GetLastError());
CloseHandle(hMapFile1);
return 1;
}

memset((PVOID)buffer, 0, sizeof(char) * BUF_SIZE);


addMsg("This is msg 1");
addMsg("This is msg 2");

_getch();
UnmapViewOfFile(pBuf);

CloseHandle(hMapFile1);

return 0;
}


In Process2
// Process2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
#pragma comment(lib, "user32.lib")


/*int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}*/

#define BUF_SIZE 256
TCHAR szName1[]=TEXT("Global\\MyFileMappingObject");

int _tmain()
{
HANDLE hMapFile;
LPCTSTR pBuf;

hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
szName1); // name of mapping object

if (hMapFile == NULL)
{
_tprintf(TEXT("Could not open file mapping object (%d).\n"),
GetLastError());
return 1;
}

pBuf = (LPTSTR) MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);

if (pBuf == NULL)
{
_tprintf(TEXT("Could not map view of file (%d).\n"),
GetLastError());

CloseHandle(hMapFile);

return 1;
}

//MessageBox(NULL, pBuf, TEXT("Process2"), MB_OK);

long msgCount, curMsgNum;
char *curMsg;

memcpy(&msgCount, pBuf, sizeof(long));
curMsg = (char*)(long)&pBuf + sizeof(long);
for (curMsgNum=0; curMsgNum<msgCount;curMsgNum++)
{
printf("%s\n", curMsg);
curMsg += strlen(curMsg) + 1;
}


UnmapViewOfFile(pBuf);

CloseHandle(hMapFile);

return 0;
}





I dont know where i am wrong,Please can you help me where i am going wrong


Thanks
Sharan
GeneralRe: Regarding Memory Mapped Pin
enhzflep24-Jun-11 0:12
enhzflep24-Jun-11 0:12 
GeneralRe: Regarding Memory Mapped Pin
manju 324-Jun-11 2:07
manju 324-Jun-11 2:07 
GeneralRe: Regarding Memory Mapped Pin
manju 32-Aug-11 19:49
manju 32-Aug-11 19:49 
Questionfp:precise vs. fp:strict performance Pin
Alex_GR21-Jun-11 2:37
Alex_GR21-Jun-11 2:37 
QuestionReceive a client event when file on web server is modified Pin
pscholl21-Jun-11 0:54
pscholl21-Jun-11 0:54 
AnswerRe: Receive a client event when file on web server is modified Pin
Mark Salsbery21-Jun-11 8:18
Mark Salsbery21-Jun-11 8:18 
GeneralRe: Receive a client event when file on web server is modified Pin
pscholl22-Jun-11 1:34
pscholl22-Jun-11 1:34 
GeneralRe: Receive a client event when file on web server is modified Pin
Mark Salsbery22-Jun-11 7:55
Mark Salsbery22-Jun-11 7:55 
QuestionSort the list of files available in a folder. Pin
lucky_122120-Jun-11 23:02
lucky_122120-Jun-11 23:02 
AnswerRe: Sort the list of files available in a folder. Pin
Cedric Moonen21-Jun-11 0:14
Cedric Moonen21-Jun-11 0:14 
AnswerRe: Sort the list of files available in a folder. Pin
Richard MacCutchan21-Jun-11 2:03
mveRichard MacCutchan21-Jun-11 2:03 
GeneralRe: Sort the list of files available in a folder. Pin
lucky_122121-Jun-11 2:10
lucky_122121-Jun-11 2:10 
GeneralRe: Sort the list of files available in a folder. Pin
Richard MacCutchan21-Jun-11 2:59
mveRichard MacCutchan21-Jun-11 2:59 
AnswerRe: Sort the list of files available in a folder. Pin
వేంకటనారాయణ(venkatmakam)21-Jun-11 3:05
వేంకటనారాయణ(venkatmakam)21-Jun-11 3:05 
QuestionQuestion about Getting Main Icon using Findresource() Pin
lek25820-Jun-11 21:51
lek25820-Jun-11 21:51 
AnswerRe: Question about Getting Main Icon using Findresource() Pin
Richard MacCutchan21-Jun-11 2:01
mveRichard MacCutchan21-Jun-11 2:01 
AnswerRe: Question about Getting Main Icon using Findresource() Pin
MicroVirus21-Jun-11 5:50
MicroVirus21-Jun-11 5:50 

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.