Link to home
Start Free TrialLog in
Avatar of Brian Dumas
Brian DumasFlag for United States of America

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:

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;
};

Open in new window


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
Avatar of sarabande
sarabande
Flag of Luxembourg image

you may look at the following article which describes how you have to define structures in c# that were compatible to C/C++ structures.

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
Avatar of Brian Dumas

ASKER

Hello Sara, I will look it up and possibly try it. Thanks
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial