how to transfer read/write attribute to win32 api

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
ole111Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bsmuehmerCommented:
I can't help You much, but provide You with a link...

Did You have a look at:
        http://www.pinvoke.net/

The link for MapViewOfFile is:
        http://www.pinvoke.net/default.aspx/kernel32.MapViewOfFile

...maybe they can help You a bit.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ole111Author Commented:
I love Microsoft. The answer to my problem is this:

In CreateFileMapping the write access parameter is from enum PageProtection : uint {
  ...
   ReadWrite =    0x04,
...
}
In OpenFileMapping and in MapViewOfFile the wrtite access parameter is
const UInt32 SECTION_MAP_WRITE = 0x0002;
const UInt32 SECTION_MAP_READ = 0x0004;

Many are simply not aware of that, hence the confusion.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.