473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

.NET inter process shared memory

I'm using SendMessage(...) to send a message to all other process that might run. It works well. My problem is when I try to pass data using shared memory. Here is my code.

In the 1st process, I use this to send the msg

BinaryFormatter b = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
b.Serialize(stream, str);
stream.Flush();
int dataSize =(int) stream.Length;
byte[] data = new byte[dataSize];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(data, 0, dataSize);
IntPtr ptrData = Marshal.AllocHGlobal(dataSize);

Marshal.Copy(data, 0, ptrData, dataSize);


SendMessage(0xffff, lMsg, ptrData, Convert.ToInt64(dataSize));


In the other process i use this


protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

if ((UInt32)m.Msg == theCloseMsgId)
{
int bufferLenght = m.LParam.ToInt32();
byte[] data = new byte[bufferLenght];
Marshal.Copy(m.WParam, data, 0, bufferLenght);

BinaryFormatter b = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
stream.Write(data, 0, data.Length);
stream.Seek(0, SeekOrigin.Begin);
string str = (string)b.Deserialize(stream, null);
forceClose = true;
Close();

}
} //WndProc

I tried this in the same process and it works but in two differents process, the shared memory that was allocated with Marshal.AllocHGlobal() has changed. Anyone can help me ? Maybe another way to create the memory ?
Mar 18 '08 #1
0 1278

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steve T | last post by:
Hi, I am developing some software in C++ to access a PMC card in a PC. The PMC card comes with a set of C++ libs to access it and to handle interrupts from it. I am therefore writing entirely in...
4
by: Viper Venom | last post by:
Dear All: I am trying to write an application that consist 2 executables 1) Server.exe 2) Client.exe I start the server.exe first and then start the two client exe by code and kill both of...
7
by: A.M | last post by:
Hi, What is the best way to implemet Inter Process Communication in .NET ? I developed two programs and I want to have them talk to each other. Thanks, Alan
4
by: Paul Baker | last post by:
Hello All, This is my first post so apologies if this is the wrong newsgroup. I'm designing software for a platform that will sit on a CAN bus. There will be three separate programs running...
35
by: Alex Martelli | last post by:
Having fixed a memory leak (not the leak of a Python reference, some other stuff I wasn't properly freeing in certain cases) in a C-coded extension I maintain, I need a way to test that the leak is...
1
by: Michael L | last post by:
Dear all, I have an ActiveX control that is hosted by a C# webbrowser control. The activex is written in C++ and I need a way to communicate between the activex and other c# applications or c++...
8
by: =?ISO-8859-15?B?TnXxbw==?= I.G | last post by:
Hello to everybody: I'm trying to get some information about "process management". Let's explain a little... I want to write some code that allows me to execute some "aplications" and collect...
28
by: Jon Davis | last post by:
We're looking at running a memory-intensive process for a web site as a Windows service in isolation of IIS because IIS refuses to consume all of the available physical RAM. Considering remoting to...
8
by: JamesHoward | last post by:
I am looking for a way of performing inter process communication over XML between a python program and something else creating XML data. What is the best way of performing this communication? I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.