So I have a first process (process1.cpp) which takes the list of the current processes in the system and should write them in the shared memory alongside their PID and PPID:
addr = (LPTSTR)MapViewOfFile(hMapFile,
FILE_MAP_ALL_ACCESS,
0,
0,
256);
And I make the writing like this:
int j = 0;
do
{
if (pe32.cntThreads < 3)
{
char currentProcessExeName = (char)pe32.szExeFile;
char currentProcessID = (char)pe32.th32ProcessID;
char currentProcessParentID = (char)pe32.th32ParentProcessID;
addr = (LPCTSTR)currentProcessExeName;
addr = (LPCTSTR)currentProcessID;
addr = (LPCTSTR)currentProcessParentID;
j = j + 3;
}
} while (Process32Next(hProcessSnap, &pe32));
Then, in the second process (process2.cpp) I want to read that array. The problem is that I get either 'can't read memory' error, or null values.
Here's how I make the read in the second process:
addr = (LPTSTR)MapViewOfFile(hMapFile,
FILE_MAP_ALL_ACCESS,
0,
0,
BUF_SIZE);
if (addr == NULL)
{
_tprintf(TEXT("Could not map view of file (%d).\n"), GetLastError());
CloseHandle(hMapFile);
return 1;
}
for (int i = 0; i < sizeof(addr); i = i + 3)
{
printf("\nProcess: %S [%d] [%d] \n", addr[i], addr[i + 1], addr[i + 2]);
}
Any fix for this ?
P.S.: I've posted as less code as possible not to load the page too much. If needed, I will post more.