我一直在审查Pavel Yosifovich的书籍和录像。 我试图写出一个纯粹的C方案,它制造了一种ker子,并且允许一个案文从一个过程到另一个过程。 我的代码如下,但出于某种原因,读到数据的方案总是要求开放式打字,最后错误是2,没有发现。 我跑了温和派,我的共有主题在两场会议中显示。 我并不认为这是一个安全问题,因为没有发现错误,我试图将来源改变为当地货币共同交易,但这没有改变。 我也试图在行政指挥中迅速行动,但至今没有工作。 似乎像现在这样说的是没有找到档案,所以它就成了一条路。 下面是两个方案的准则。
<
#include <windows.h>
#include <stdio.h>
#include <string.h>
int main() {
HANDLE hFileMapping;
LPVOID lpFileMap;
char buffer[] = "Windows System Programming is fun!";
hFileMapping = CreateFileMapping(
INVALID_HANDLE_VALUE,
NULL,
PAGE_READWRITE,
0,
sizeof(buffer),
L"MySharedMemory"
);
if (hFileMapping == NULL) {
printf("Error creating file mapping: %d
", GetLastError());
return 1;
}
lpFileMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, 0);
if (lpFileMap == NULL) {
printf("Error mapping view of file: %d
", GetLastError());
CloseHandle(hFileMapping);
return 1;
}
strcpy((char*)lpFileMap, buffer);
printf("Data written to shared memory. Press Enter to exit...
");
getchar();
UnmapViewOfFile(lpFileMap);
CloseHandle(hFileMapping);
return 0;
}
#include <windows.h>
#include <stdio.h>
int main() {
HANDLE hFileMapping;
LPVOID lpFileMap;
hFileMapping = OpenFileMapping(
FILE_MAP_READ,
FALSE,
L"MySharedMemory"
);
if (hFileMapping == NULL) {
printf("Error opening file mapping: %d
", GetLastError());
getchar();
return 1;
}
lpFileMap = MapViewOfFile(
hFileMapping,
FILE_MAP_READ,
0,
0,
0,
0
);
if (lpFileMap == NULL) {
printf("Error mapping view of file: %d
", GetLastError());
CloseHandle(hFileMapping);
getchar();
return 1;
}
printf("Received message: %s
", (char*)lpFileMap);
UnmapViewOfFile(lpFileMap);
getchar();
CloseHandle(hFileMapping);
return 0;
}
最新法典,但仍未奏效。
#include <windows.h>
#include <stdio.h>
#include <string.h>
int main() {
HANDLE hFileMapping;
LPVOID lpFileMap;
char buffer[] = "Windows System Programming is fun!";
hFileMapping = CreateFileMapping(
INVALID_HANDLE_VALUE,
NULL,
PAGE_READWRITE,
0,
1 << 12,
L"MySharedMemory"
);
if (hFileMapping == NULL) {
printf("Error creating file mapping: %d
", GetLastError());
return 1;
}
lpFileMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, 0);
if (lpFileMap == NULL) {
printf("Error mapping view of file: %d
", GetLastError());
CloseHandle(hFileMapping);
return 1;
}
strcpy((char*)lpFileMap, buffer);
printf("Data written to shared memory. Press Enter to exit...
");
getchar();
UnmapViewOfFile(lpFileMap);
CloseHandle(hFileMapping);
return 0;
}
#include <windows.h>
#include <stdio.h>
int main() {
HANDLE hFileMapping;
LPVOID lpFileMap;
//hFileMapping = OpenFileMapping(
// FILE_MAP_READ,
// FALSE,
// L"MySharedMemory"
// );
hFileMapping = CreateFileMapping(
INVALID_HANDLE_VALUE,
NULL,
PAGE_READWRITE,
0,
1 << 12,
L"MySharedMemory"
);
if (hFileMapping == NULL) {
printf("Error opening file mapping: %d
", GetLastError());
getchar();
return 1;
}
lpFileMap = MapViewOfFile(
hFileMapping,
FILE_MAP_READ,
0,
0,
1 << 12
);
if (lpFileMap == NULL) {
printf("Error mapping view of file: %d
", GetLastError());
CloseHandle(hFileMapping);
getchar();
return 1;
}
printf("Received message: %s
", (char*)lpFileMap);
UnmapViewOfFile(lpFileMap);
getchar();
CloseHandle(hFileMapping);
return 0;
}