Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages
Started by Colin B Maharaj
Thu, 26 Jun 2008 10:32
Memory mapped files in a Service
Author: Colin B Maharaj
Date: Thu, 26 Jun 2008 10:32
Date: Thu, 26 Jun 2008 10:32
28 lines
1792 bytes
1792 bytes
Hi folks, I recently had to fix a bug where my memory mapped file that was running in my service application was not visible to my foreground application. To fix this I had to add Global to the name like this..... From: "MMAPFILE" To: "Global\\MMAPFILE" Had to do this to both my service and foreground application. Now in some cases it works fine, e.g. in my development environment it was not necessary for me to make these changes. It seems to be a namespace issue http://blogs.msdn.com/maartenb/archive/2008/05/07/memory-mapped-files-from-xp-to-vista.aspx In this article they articulate the problem - but with vista, however it also applies, "at times", to XP services. The real problem being here is "at times". Question: (Finally) How do I know that the operating system will run my service and create memory mapped files within a separate namespace or not. thanks..
Re: Memory mapped files in a Service
Author: Mike Collins
Date: Thu, 26 Jun 2008 15:57
Date: Thu, 26 Jun 2008 15:57
58 lines
3116 bytes
3116 bytes
Colin, From my understanding, if you create a memory mapped file (or mutex or other kernel object) and you do not prefix it with anything, it is assumed to be "Local". Therefore, it is local for the session that it is created in. In vista this is more of a problem becuase all the services run in session 0. therefore if you create a MMF in session 0, with no prefixing, it is local to session 0 and NOT accessible / visiable outside that session. Therefore, to get the system to function as you require, you just prefix it with "Global\\". This should work in all cases, regardless of Vista or XP (the only exception being Windows 2K <). I did not notice anothing in the article that suggested "at times". I have a similar situation and it seems ot work in both Vista and XP. Have you checked which part of your process is not working? Is it the initial CreateFileMapping or the OpenFileMapping? What does GetLastError() return? What does ProcExplorer.exe show up as the file map name? How are you controlling access to your MMF? Mike C "Colin B Maharaj" <noreply@myhost.com> wrote in message news:48637046$1@newsgroups.borland.com... > Hi folks, > I recently had to fix a bug where my memory mapped file > that was running in my service application was not > visible to my foreground application. > > To fix this I had to add Global to the name like this..... > > From: "MMAPFILE" > To: "Global\\MMAPFILE" > > Had to do this to both my service and foreground application. > > Now in some cases it works fine, e.g. in my development environment > it was not necessary for me to make these changes. It seems to > be a namespace issue > > http://blogs.msdn.com/maartenb/archive/2008/05/07/memory-mapped-files-from-xp-to-vista.aspx > > In this article they articulate the problem - but with vista, however it > also applies, "at times", to XP services. The real problem being here is > "at times". > > > Question: (Finally) > How do I know that the operating system will run my service and > create memory mapped files within a separate namespace or not. > > thanks.. >
Re: Memory mapped files in a Service
Author: Colin B Maharaj
Date: Sat, 28 Jun 2008 12:11
Date: Sat, 28 Jun 2008 12:11
90 lines
3345 bytes
3345 bytes
Hi Mike, thanks for the reply,
Mike Collins wrote:
> Colin,
>
> "Global\\". This should work in all cases, regardless of Vista or XP (the
> only exception being Windows 2K <). I did not notice anothing in the
> article that suggested "at times".
The "at times" is what I have experienced in XP...
BTW: does Windows 2K < include Windows 2K or just NT/9x.
I have a similar situation and it seems
> ot work in both Vista and XP.
>
> Have you checked which part of your process is not working?
>
The fact is that all objects are created without error.
However when you open the named object it simply says
file not found.
> Is it the initial CreateFileMapping or the OpenFileMapping?
>
Open file mapping ...
> What does GetLastError() return?
>
.... File Not found.
> What does ProcExplorer.exe show up as the file map name?
>
Have to double check this....
> How are you controlling access to your MMF?
what do you mean by this? This is my code...
..........
// Code in Service
bool Is9x = (Win32Platform == VER_PLATFORM_WIN32_WINDOWS);
if (Is9x == false)//nt/2000/2003 server/xp pro/
{
//Beep(1000,20);
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = TRUE;
mmHandle = CreateFileMapping((HANDLE) 0xFFFFFFFF,
&sa, PAGE_READWRITE, 0, mmSize, __TEXT(mmName));
}
else
{
mmHandle = CreateFileMapping((HANDLE) 0xFFFFFFFF,
NULL, PAGE_READWRITE, 0, mmSize, __TEXT(mmName));
}
...........
//Code in Front end client
hFileMapT = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE,
FALSE, __TEXT(mmName));
>
> Mike C
>
>
> "Colin B Maharaj" <noreply@myhost.com> wrote in message
> news:48637046$1@newsgroups.borland.com...
>> Hi folks,
>> I recently had to fix a bug where my memory mapped file
>> that was running in my service application was not
>> visible to my foreground application.
>>
>> To fix this I had to add Global to the name like this.....
>>
>> From: "MMAPFILE"
>> To: "Global\\MMAPFILE"
>>
Re: Memory mapped files in a Service
Author: Mike Collins
Date: Sun, 29 Jun 2008 01:18
Date: Sun, 29 Jun 2008 01:18
44 lines
2466 bytes
2466 bytes
Hay Colin, most of what i know is based on what remy has told me on this forum, but here goes... > BTW: does Windows 2K < include Windows 2K or just NT/9x. - this includes Win2K - Global\\ is not valid on 2k > The fact is that all objects are created without error. > However when you open the named object it simply says > file not found. - Yep, the objects will be created without error - this does not mean that they are *visible* from outside the session that they are created in > Open file mapping ... > .... File Not found. - this pretty much confirms what we're saying... > What does ProcExplorer.exe show up as the file map name? > Have to double check this.... - ProcExplorer is a god-send... Check it out from SysInternals... > mmHandle = CreateFileMapping((HANDLE) 0xFFFFFFFF, > &sa, PAGE_READWRITE, 0, mmSize, __TEXT(mmName)); - does your mmName contain the "Global\\" prefix? if not, include it, perminantly and see what you get - if works for me... > hFileMapT = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE, > FALSE, __TEXT(mmName)); - Like wise, make sure mmName here also contains the "Global\\" prefix. Another point worth mentioning is that you should, depending on what you are doing with your MMF, protect access to it using a mutex, because there is the possibility that you *server Sis writting to the MMF, while yout *client* is trying to access it... HTH Mike C
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads