troubleshooting Question

how to transfer read/write attribute to win32 api

Avatar of ole111
ole111 asked on
C#
2 Comments1 Solution260 ViewsLast Modified:
Hi

I have C# and C++ programs and I am using memory mapping to interact between them.
I use WinAPi from both programs. Now I cannot write from C# program to the memory file, although I can read what has been written from c++ program.
I STRONGLY suspect that the problem is that I simply give a wrong number as an argument for read/write permissions in C# program.
In C++ it is simple, the API is used straight, e.g.
MapViewOfFile(handle,  
                        FILE_MAP_ALL_ACCESS, // read/write permission
                        0,                  
                        0,                  
                        size);  
 
In C# I obviously cannot use FILE_MAP_ALL_ACCESS or PAGE_READWRITE

so I use int, e.g.

[DllImport("Kernel32.dll",EntryPoint="MapViewOfFile",SetLastError=true,CharSet=CharSet.Unicode)]
internal static extern IntPtr MapViewOfFile(IntPtr handle, uint r_w_access, uint offset_h, uint offset_low, uint size);

and I simply send number 4 or 2 as r_w_access. I don't know why these spesific numbers (found somewhere on the Internet).
So my question is - there should be a more reliable way to pass access parameter from C# to WinAPI functions. What is it?

thnx
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros