I'm trying to create a region of shared memory using memory-mapped files
When I compile my code I get this error:
"invalid conversion from void* to char*"
"initializing argument 1 of int sprintf(char*, const char*, ....)"
When I replace
CODE
sprintf(lpMapAddress, "<output 1>");
with
CODE
printf("%s", lpMapAddress, "<output 1>");
there isn't an error, but nothing is written to input.map.
I know there is something small that I'm missing. Can anybody please help me?
My code:
CODE
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
HANDLE hFile, hMapFile;
LPVOID lpMapAddress;
char* lp;
hFile = CreateFile("input.map", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
hMapFile = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, TEXT("SharedObject"));
lpMapAddress = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
sprintf(lpMapAddress, "<output 1>");
UnmapViewOfFile(lpMapAddress);
CloseHandle(hFile);
CloseHandle(hMapFile);
}
#include <stdio.h>
int main(int argc, char *argv[])
{
HANDLE hFile, hMapFile;
LPVOID lpMapAddress;
char* lp;
hFile = CreateFile("input.map", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
hMapFile = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, TEXT("SharedObject"));
lpMapAddress = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
sprintf(lpMapAddress, "<output 1>");
UnmapViewOfFile(lpMapAddress);
CloseHandle(hFile);
CloseHandle(hMapFile);
}
Thanks