Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Shared memory

Posted on 2001-06-19
20
Medium Priority
?
413 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

610 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