?
Solved

Shared memory

Posted on 2001-06-19
20
Medium Priority
?
405 Views
Last Modified: 2008-02-26
Hi I am using a shared memory.I created the shared memory
in one application by using CreateFileMapping.
When I open this shared memory in another application
by OpenFileMapping , it returning NULL handle and the errorcode is 5.

 I am using the following code
     hMemory = OpenFileMapping(
                      FILE_MAP_ALL_ACCESS,
                   FALSE,
                   MEMORY_TABLE_NAME      // name of map  object
     
                       );

Can somebody tell me how I can open the share memory.

thanks in advance.
0
Comment
Question by:vinodpilley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 5
  • 3
20 Comments
 
LVL 5

Expert Comment

by:robpitt
ID: 6207065
Is the call to CreateFileMapping working ok?

Also what did you specifiy for the hFile when you called CreateFileMapping? If you specified a custom file, what access was that file opened with?

Rob
0
 

Author Comment

by:vinodpilley
ID: 6207078
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.

     *phMemory = CreateFileMapping(
                      (HANDLE)INVALID_HANDLE_VALUE, // use paging file
                   NULL,                 // no security attributes
                   PAGE_READWRITE,       // read/write access
                   0,                    // size: high 32-bits
                   (sizeof SharedReqRespTable) * MAX_TABLE_SIZE,      // size: low 32-bits
                   MEMORY_TABLE_NAME      // name of map object
                    );    
0
 

Author Comment

by:vinodpilley
ID: 6207097
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.

     *phMemory = CreateFileMapping(
                      (HANDLE)INVALID_HANDLE_VALUE, // use paging file
                   NULL,                 // no security attributes
                   PAGE_READWRITE,       // read/write access
                   0,                    // size: high 32-bits
                   (sizeof SharedReqRespTable) * MAX_TABLE_SIZE,      // size: low 32-bits
                   MEMORY_TABLE_NAME      // name of map object
                    );    
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vinodpilley
ID: 6207160
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.

     *phMemory = CreateFileMapping(
                      (HANDLE)INVALID_HANDLE_VALUE, // use paging file
                   NULL,                 // no security attributes
                   PAGE_READWRITE,       // read/write access
                   0,                    // size: high 32-bits
                   (sizeof SharedReqRespTable) * MAX_TABLE_SIZE,      // size: low 32-bits
                   MEMORY_TABLE_NAME      // name of map object
                    );    
0
 

Author Comment

by:vinodpilley
ID: 6207180
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.

     *phMemory = CreateFileMapping(
                      (HANDLE)INVALID_HANDLE_VALUE, // use paging file
                   NULL,                 // no security attributes
                   PAGE_READWRITE,       // read/write access
                   0,                    // size: high 32-bits
                   (sizeof SharedReqRespTable) * MAX_TABLE_SIZE,      // size: low 32-bits
                   MEMORY_TABLE_NAME      // name of map object
                    );    
0
 

Author Comment

by:vinodpilley
ID: 6207213
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.

     *phMemory = CreateFileMapping(
                      (HANDLE)INVALID_HANDLE_VALUE, // use paging file
                   NULL,                 // no security attributes
                   PAGE_READWRITE,       // read/write access
                   0,                    // size: high 32-bits
                   (sizeof SharedReqRespTable) * MAX_TABLE_SIZE,      // size: low 32-bits
                   MEMORY_TABLE_NAME      // name of map object
                    );    
0
 

Author Comment

by:vinodpilley
ID: 6207224
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.

     *phMemory = CreateFileMapping(
                      (HANDLE)INVALID_HANDLE_VALUE, // use paging file
                   NULL,                 // no security attributes
                   PAGE_READWRITE,       // read/write access
                   0,                    // size: high 32-bits
                   (sizeof SharedReqRespTable) * MAX_TABLE_SIZE,      // size: low 32-bits
                   MEMORY_TABLE_NAME      // name of map object
                    );    
0
 

Author Comment

by:vinodpilley
ID: 6207259
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.

     *phMemory = CreateFileMapping(
                      (HANDLE)INVALID_HANDLE_VALUE, // use paging file
                   NULL,                 // no security attributes
                   PAGE_READWRITE,       // read/write access
                   0,                    // size: high 32-bits
                   (sizeof SharedReqRespTable) * MAX_TABLE_SIZE,      // size: low 32-bits
                   MEMORY_TABLE_NAME      // name of map object
                    );    
0
 
LVL 30

Expert Comment

by:Axter
ID: 6207423
vinodpilley,
When openning your question on a current session, please use the RELOAD link on the upper left corner of your question.  That will stop the repeat post.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6207437
How are you verifing that CreateFileMapping() is occuring before the other application does the OpenFileMapping()?

Make sure that you are using the same name for both functions.
Check the following veriable MEMORY_TABLE_NAME?
Make sure it's exactly the same.
0
 

Author Comment

by:vinodpilley
ID: 6211050
I am using CreateFileMapping() in one service program.
First I am running that service and then I am running my second exe which is opening that table.Now what I  found that when I open the table with read permission , it will return successfull.but when I am open that table with  FILE_MAP_ALL_ACCESS
permission ,it will returning access deny error code.
So there must be some permission problem.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6211081
lpFileMappingAttributes
Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpFileMappingAttributes is NULL, the handle cannot be inherited.
Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the new file-mapping object. If lpFileMappingAttributes is NULL, the file-mapping object gets a default security descriptor.

0
 
LVL 30

Expert Comment

by:Axter
ID: 6211088
Try declaring a SECURITY_ATTRIBUTES variable, and setting it to zero.  Then pass that instead of NULL.

SECURITY_ATTRIBUTES sa;
memset(&sa,0,sizeof(sa));
0
 

Author Comment

by:vinodpilley
ID: 6211111
I am using CreateFileMapping() in one service program.
First I am running that service and then I am running my second exe which is opening that table.Now what I  found that when I open the table with read permission , it will return successfull.but when I am open that table with  FILE_MAP_ALL_ACCESS
permission ,it will returning access deny error code.
So there must be some permission problem.
0
 

Author Comment

by:vinodpilley
ID: 6211148
I am using CreateFileMapping() in one service program.
First I am running that service and then I am running my second exe which is opening that table.Now what I  found that when I open the table with read permission , it will return successfull.but when I am open that table with  FILE_MAP_ALL_ACCESS
permission ,it will returning access deny error code.
So there must be some permission problem.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6211169
vinodpilley,
When openning your question on a current session, please use the RELOAD link on the upper left corner
of your question.  That will stop the repeat post.

You will continue to repost your same message over and over again, if you don't use the Reload Question link.
0
 

Author Comment

by:vinodpilley
ID: 6211272
I am using CreateFileMapping() in one service program.
First I am running that service and then I am running my second exe which is opening that table.Now what I  found that when I open the table with read permission , it will return successfull.but when I am open that table with  FILE_MAP_ALL_ACCESS
permission ,it will returning access deny error code.
So there must be some permission problem.
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6212310
A service? Ahhh, in that case you need to ensure you use a null DACL in the security descriptor when you create the mapping, otherwise all non-services only be allowed read access.

Try this:

SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;    

InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd,TRUE,(PACL)NULL,FALSE);

sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=&sd;
sa.bInheritHandle=TRUE;

CreateFileMapping(INVALID_HANDLE_VALUE,&sa,....
0
 
LVL 5

Accepted Solution

by:
robpitt earned 80 total points
ID: 6212338
PS there used to be a KB article for this but it seems to have disappeared. The number is Q193073.
0
 

Author Comment

by:vinodpilley
ID: 6212550
Thanks very much for helping me ,I really appreciate
it.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question