vinodpilley
asked on
Shared memory
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.
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.
ASKER
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL UE, // 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
);
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL
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
);
ASKER
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL UE, // 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
);
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL
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
);
ASKER
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL UE, // 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
);
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL
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
);
ASKER
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL UE, // 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
);
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL
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
);
ASKER
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL UE, // 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
);
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL
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
);
ASKER
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL UE, // 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
);
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL
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
);
ASKER
Yes the CreateFileMapping worked ok.
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL UE, // 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
);
Following code I used to create shared memory.
*phMemory = CreateFileMapping(
(HANDLE)INVALID_HANDLE_VAL
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
);
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.
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.
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.
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.
ASKER
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.
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.
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.
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.
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));
SECURITY_ATTRIBUTES sa;
memset(&sa,0,sizeof(sa));
ASKER
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.
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.
ASKER
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.
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.
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.
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.
ASKER
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.
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.
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;
InitializeSecurityDescript or(&sd,SEC URITY_DESC RIPTOR_REV ISION);
SetSecurityDescriptorDacl( &sd,TRUE,( PACL)NULL, FALSE);
sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=&s d;
sa.bInheritHandle=TRUE;
CreateFileMapping(INVALID_ HANDLE_VAL UE,&sa,... .
Try this:
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
InitializeSecurityDescript
SetSecurityDescriptorDacl(
sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=&s
sa.bInheritHandle=TRUE;
CreateFileMapping(INVALID_
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much for helping me ,I really appreciate
it.
it.
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