所以我有一个第一个进程(process1.cpp),它获取系统中当前进程的列表,并应将它们与PID和PPID一起写在共享内存中:
addr = (LPTSTR)MapViewOfFile(hMapFile,
FILE_MAP_ALL_ACCESS,
0,
0,
256);
我写这样的文字:
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));
然后,在第二个进程(process2.cpp)中,我想读取该数组。问题是我得到'无法读取内存'错误或空值。
以下是我在第二个过程中进行阅读的方法:
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]);
}
对此有何修复?
P.S。:我发布尽可能少的代码,不要过多加载页面。如果需要,我会发布更多。