M
Martin Priebe
Hi,
i tried to use MMF to communicate between 2 processes.
i want to transfer a bitmap between the 2 processes.
i created a mmf in my first process
public IntPtr CreateMMF(FileAccess access, int size)
{
if (size < 0)
throw new ArgumentException("The size parameter should be a number greater
than Zero.");
IntPtr memoryFileHandle = CreateFileMapping(0xFFFFFFFF, IntPtr.Zero,
(uint)access, 0, (uint)size, "MMF");
if (memoryFileHandle == IntPtr.Zero)
throw new Exception("Creating Shared Memory failed.");
return memoryFileHandle;
}
i mapped it and write the graphic to it
IntPtr mappedViewHandle = MapViewOfFile(mmfHandle, (uint)FILE_MAP_WRITE, 0,
0, 0);
if (mappedViewHandle == IntPtr.Zero)
throw new Exception("Creating a view of Shared Memory failed.");
Marshal.WriteIntPtr(mappedViewHandle, gfxScreenshot.GetHdc());
UnmapViewOfFile(mappedViewHandle);
CloseHandle((uint)mappedViewHandle);
my other process mapped the file but throw an exception "not enough memory"
IntPtr mappedFileHandle = OpenFileMapping((int)FileAccess.ReadWrite, false,
"MMF");
if (mappedFileHandle == IntPtr.Zero)
throw new Exception("Opening the Shared Memory for Read failed.");
//here the Exception is thrown
IntPtr mappedViewHandle = MapViewOfFile(mappedFileHandle,
(uint)FILE_MAP_READ, 0, 0, 0);
if (mappedViewHandle == IntPtr.Zero)
throw new Exception("Creating a view of Shared Memory failed.");
IntPtr windowHandle = Marshal.ReadIntPtr(mappedViewHandle);
if (windowHandle == IntPtr.Zero)
throw new ArgumentException("Reading from the specified address in Shared
Memory failed.");
UnmapViewOfFile(mappedViewHandle);
CloseHandle((uint)mappedFileHandle);
return windowHandle;
CreateMappedFile i use a size of 200000. (nearly 200 KB)
Pleayse help me.
greetings
Martin
i tried to use MMF to communicate between 2 processes.
i want to transfer a bitmap between the 2 processes.
i created a mmf in my first process
public IntPtr CreateMMF(FileAccess access, int size)
{
if (size < 0)
throw new ArgumentException("The size parameter should be a number greater
than Zero.");
IntPtr memoryFileHandle = CreateFileMapping(0xFFFFFFFF, IntPtr.Zero,
(uint)access, 0, (uint)size, "MMF");
if (memoryFileHandle == IntPtr.Zero)
throw new Exception("Creating Shared Memory failed.");
return memoryFileHandle;
}
i mapped it and write the graphic to it
IntPtr mappedViewHandle = MapViewOfFile(mmfHandle, (uint)FILE_MAP_WRITE, 0,
0, 0);
if (mappedViewHandle == IntPtr.Zero)
throw new Exception("Creating a view of Shared Memory failed.");
Marshal.WriteIntPtr(mappedViewHandle, gfxScreenshot.GetHdc());
UnmapViewOfFile(mappedViewHandle);
CloseHandle((uint)mappedViewHandle);
my other process mapped the file but throw an exception "not enough memory"
IntPtr mappedFileHandle = OpenFileMapping((int)FileAccess.ReadWrite, false,
"MMF");
if (mappedFileHandle == IntPtr.Zero)
throw new Exception("Opening the Shared Memory for Read failed.");
//here the Exception is thrown
IntPtr mappedViewHandle = MapViewOfFile(mappedFileHandle,
(uint)FILE_MAP_READ, 0, 0, 0);
if (mappedViewHandle == IntPtr.Zero)
throw new Exception("Creating a view of Shared Memory failed.");
IntPtr windowHandle = Marshal.ReadIntPtr(mappedViewHandle);
if (windowHandle == IntPtr.Zero)
throw new ArgumentException("Reading from the specified address in Shared
Memory failed.");
UnmapViewOfFile(mappedViewHandle);
CloseHandle((uint)mappedFileHandle);
return windowHandle;
CreateMappedFile i use a size of 200000. (nearly 200 KB)
Pleayse help me.
greetings
Martin