hassanayoub85
asked on
Accessing c++ variables from c#?
Dear all,
I have a c++ application and another c# application, 2 processes.
I want to access the data from the c++ application from c#.
Any idea on how to do that?
I have a c++ application and another c# application, 2 processes.
I want to access the data from the c++ application from c#.
Any idea on how to do that?
It is not clear what you want to achieve. Can you please clarify. Do you need a some sort of inter-process communication between these two programs? Is it some sort of client-server environment? Do you need to access common data? Do you need to read the information from the program GUI? Do you have access to both program code? Are these program on the same machine?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
chaau:
Yes, both exes are on same machine. have source code for them.
both are on c#.
I want to have in the result 2 processes running, 1 is doing calculations and return values to the other process, and the other process give orders to process 1.
So Only variable reading from the 2 processes.
Sara:
I need your cooperation and help with the most easy way plz
Note: I already tried write to file and read from it, but it is so slow, I am working on 40millisecond timer
Yes, both exes are on same machine. have source code for them.
both are on c#.
I want to have in the result 2 processes running, 1 is doing calculations and return values to the other process, and the other process give orders to process 1.
So Only variable reading from the 2 processes.
Sara:
I need your cooperation and help with the most easy way plz
Note: I already tried write to file and read from it, but it is so slow, I am working on 40millisecond timer
the easiest way is to write to file and read from it. but as you have seen it is the slowest way.
the next easier methods are either memory mapped files via System.IO.MemoryMappedFile s or you WINAPI to allocate global memory, store the data there, and then pass the handle to the other process by windows message. the other process then could access the memory using the handle.
Sara
the next easier methods are either memory mapped files via System.IO.MemoryMappedFile
IntPtr hglobal = Marshal.AllocHGlobal(1000);
IntPtr ptr = GlobalLock(hglobal);
// now use Marshal copy functions to copy the data to global memory
...
// send the handle to other process.
// you would need its window handle what could be retrieved by FindWindow
IntPtr uid = RegisterWindowMessage("MyWindowID");
SendMessage(hwndProc, uid, hglobal, 0);
// when SendMessage returned the other process has fetched the data
GlobalUnlock(hglobal);
Marshal.FreeHGlobal(hglobal);
Sara