Brian Dumas
asked on
C++ Memory Mapped File accessed from C#
Hello Experts, I have a routine in a C++ application the creates a named  shared memory view of a structure:
The C++ application puts data into the named shared memory structure and then sets a windows named event for another process to read the same structure. That other process was written in C++ and works fine. I now need to do the same thing as the reading process, but in c#. Can you tell me how to create a TEST_STRUCT variable in c# that can be used to access the C++ named shared memory?
Thanks, Brian
Windows 7 Pro
VS2013
struct TEST_STRUCT
{
long tnum;
unsigned long pass_count;
unsigned long fail_count;
unsigned long try_count;
double sum_result;
double sumsq_result;
double min;
double max;
unsigned histogram[HISTOGRAM_SIZE];
bool tested;
bool passed;
double last_result;
};
The C++ application puts data into the named shared memory structure and then sets a windows named event for another process to read the same structure. That other process was written in C++ and works fine. I now need to do the same thing as the reading process, but in c#. Can you tell me how to create a TEST_STRUCT variable in c# that can be used to access the C++ named shared memory?
Thanks, Brian
Windows 7 Pro
VS2013
ASKER
Hello Sara, I will look it up and possibly try it. Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://msdn.microsoft.com/en-us/library/aa288471(v=vs.71).aspx
generally the winapi functions CreateFileMapping and MapViewOfFile can be used in c# as well as they were not handling structures but only buffers i. e. byte arrays of a given length. nevertheless if you already have a c++ module you may think of creating a c++ dll which is mixed-code that combines both managed c++ and native c++ (search for IJW "it just works" for samples) and so allows access from both the c++ world and the .net
Sara